Add missing delete() method to IChannel; Fixes #105

This commit is contained in:
Szymon Uglis 2021-02-16 19:50:51 +01:00
parent 3643e239bb
commit 3a22fa65e7
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
2 changed files with 15 additions and 0 deletions

View file

@ -33,6 +33,9 @@ abstract class IChannel extends SnowflakeEntity implements Disposable {
}
}
/// Deletes channel if guild channel or closes DM if DM channel
Future<void> delete() => this.client.httpEndpoints.deleteChannel(this.id);
@override
Future<void> dispose() async {
// Empty body

View file

@ -269,6 +269,8 @@ abstract class IHttpEndpoints {
Future<GuildPreview> fetchGuildPreview(Snowflake guildId);
Future<IChannel> createGuildChannel(Snowflake guildId, ChannelBuilder channelBuilder);
Future<void> deleteChannel(Snowflake channelId);
}
class _HttpEndpoints implements IHttpEndpoints {
@ -1466,6 +1468,7 @@ class _HttpEndpoints implements IHttpEndpoints {
return Future.error(response);
}
@override
Future<IChannel> createGuildChannel(Snowflake guildId, ChannelBuilder channelBuilder) async {
final response = await _httpClient._execute(
@ -1477,4 +1480,13 @@ class _HttpEndpoints implements IHttpEndpoints {
return Future.error(response);
}
@override
Future<void> deleteChannel(Snowflake channelId) async {
final response = await _httpClient._execute(BasicRequest._new("/channels/${channelId.toString()}", method: "DELETE"));
if (response is HttpResponseError) {
return Future.error(response);
}
}
}