void HandleChannelDeleteEvent(DiscordApiData data) { Snowflake id = data.GetSnowflake("id").Value; DiscordChannelType type = (DiscordChannelType)data.GetInteger("type").Value; if (type == DiscordChannelType.DirectMessage) { // DM channel DiscordDMChannel dm; if (cache.DMChannels.TryRemove(id, out MutableDMChannel mutableDM)) { mutableDM.ClearReferences(); dm = mutableDM.ImmutableEntity; } else { dm = new DiscordDMChannel(http, data); } OnDMChannelRemoved?.Invoke(this, new DMChannelEventArgs(shard, dm)); } else if (type == DiscordChannelType.GuildText || type == DiscordChannelType.GuildVoice || type == DiscordChannelType.GuildCategory) { // Guild channel Snowflake guildId = data.GetSnowflake("guild_id").Value; DiscordGuildChannel channel; if (type == DiscordChannelType.GuildText) { if (!cache.GuildChannels.TryRemove(id, out channel)) { channel = new DiscordGuildTextChannel(http, data, guildId); } } else if (type == DiscordChannelType.GuildVoice) { if (!cache.GuildChannels.TryRemove(id, out channel)) { channel = new DiscordGuildVoiceChannel(http, data, guildId); } } else if (type == DiscordChannelType.GuildCategory) { if (!cache.GuildChannels.TryRemove(id, out channel)) { channel = new DiscordGuildCategoryChannel(http, data, guildId); } } else { throw new NotImplementedException($"Guild channel type \"{type}\" has no implementation!"); } OnGuildChannelRemoved?.Invoke(this, new GuildChannelEventArgs(shard, guildId, channel)); } }
public async Task <DiscordDMChannel[]> GetUserDMs() { DiscordApiData data = await rest.Get("users/@me/channels", "users/@me/channels").ConfigureAwait(false); DiscordDMChannel[] dms = new DiscordDMChannel[data.Values.Count]; for (int i = 0; i < dms.Length; i++) { dms[i] = new DiscordDMChannel(this, data.Values[i]); } return(dms); }
public async Task Run(string[] args) { DiscordClient client = new DiscordClient(new DiscordConfig() { Token = File.ReadAllText("token.txt", Encoding.ASCII), TokenType = TokenType.Bot, DiscordBranch = Branch.Stable, LogLevel = LogLevel.Debug, UseInternalLogHandler = true, AutoReconnect = true }); await client.Connect(); DiscordDMChannel channel = await client.CreateDM(53011839067361280); DiscordMessage dm = await client.SendMessage(channel, "Hi Master!"); Console.ReadLine(); }
internal DMChannelEventArgs(Shard shard, DiscordDMChannel channel) : base(shard) { Channel = channel; }