コード例 #1
0
        public async Task AddReactRoleAsync(ulong channelId, ulong messageId, ulong roleId, string emoji)
        {
            if (!Context.Guild.Channels.TryGetValue(channelId, out IGuildChannel guildChannel))
            {
                guildChannel = (await Context.Guild.FetchChannelsAsync()).FirstOrDefault(c => c.Id == channelId);
                if (guildChannel == null)
                {
                    await Response($"Could not locate channel with id {channelId}");

                    return;
                }
            }

            if (guildChannel is not ITextChannel channel)
            {
                await Response($"Channel {guildChannel.Name} is not a text channel");

                return;
            }

            if (await Context.Bot.GetMessageAsync(channelId, messageId) is not IMessage message)
            {
                await Response($"Could not locate message with id {messageId}");

                return;
            }

            IRole role = await Context.Bot.GetRoleAsync(Context.GuildId, roleId);

            if (role == null)
            {
                await Response($"Could not locate role with id {roleId}");

                return;
            }

            IEmoji emote = ReactService.ParseEmojiString(emoji);

            try
            {
                await message.AddReactionAsync(emote);
            }
            catch
            {
                await Response("Failed adding react to message: " + emote.GetType().FullName + " " + emote.ToString());

                return;
            }

            Context.Bot.Config
            .GetOrAddGuild(Context.GuildId)
            .GetOrAddChannel(channelId)
            .AddReactRole(messageId, emote, roleId);

            await Response($"Now tracking reacts to grant role '{role.Name}'");
        }
コード例 #2
0
 public async Task RemoveReactRoleAsync(ulong channelId, ulong messageId, string emoji)
 {
     if (Context.Bot.Config
         .GetOrAddGuild(Context.GuildId)
         .GetOrAddChannel(channelId)
         .TryRemoveReactRole(messageId, ReactService.ParseEmojiString(emoji)))
     {
         await Response("Reaction role granting removed");
     }
     else
     {
         await Response("Failed to remove reaction role. Maybe the parameters are incorrect?");
     }
 }
コード例 #3
0
        public async Task AddReactAsync(ulong channelId, ulong messageId, string emoji)
        {
            IMessage msg = await Context.Bot.GetMessageAsync(channelId, messageId);

            if (msg == null)
            {
                await Response("Message not found");

                return;
            }

            try
            {
                await msg.AddReactionAsync(ReactService.ParseEmojiString(emoji));
                await Response("React added");
            }
            catch
            {
                await Response("Failed adding react to message");
            }
        }
コード例 #4
0
 private Task OnReactionRemoved(object sender, ReactionRemovedEventArgs e)
 => ReactService.HandleReactRemovedAsync(this, e);