【问题标题】:Suggestion bot discord.py建议机器人 discord.py
【发布时间】:2021-06-28 09:10:51
【问题描述】:

我希望机器人使用 ✅ 和 ❎ 表情符号对自己的消息做出反应,以提供建议命令。这是代码。我该怎么做?

import discord
from discord.ext import commands

class suggestions(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(description = 'Add a suggestion for this community!')
    async def suggest(self, ctx, *,suggestion):

        
        await ctx.channel.purge(limit = 1)
        channel = discord.utils.get(ctx.guild.text_channels, name = '????│suggestions')

        suggestEmbed = discord.Embed(colour = 0xFF0000)
        suggestEmbed.set_author(name=f'Suggested by {ctx.message.author}', icon_url = f'{ctx.author.avatar_url}')
        suggestEmbed.add_field(name = 'New suggestion!', value = f'{suggestion}')

        await channel.send(embed=suggestEmbed)

def setup(bot):
    bot.add_cog(suggestions(bot))

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    Messageable.send 返回一个discord.Message 对象,然后你可以简单地.add_reaction

    message = await ctx.send(embed=suggestEmbed)
    
    await message.add_reaction('✅')
    await message.add_reaction('❌')
    

    注意:您需要表情符号的 unicode 才能做出反应,以简单地获取它\:{emoji}:

    参考:

    【讨论】:

      【解决方案2】:

      我,我用这个:

      @bot.command()
      async def suggestion(ctx, *, content: str):
        title, description= content.split('/')
        embed = discord.Embed(title=title, description=description, color=0x00ff40)
        channel = bot.get_channel(insert the channel ID here)
        vote = await channel.send(embed=embed)
        await vote.add_reaction("✅")
        await vote.add_reaction("❌")
        await ctx.send("your suggestion has been send")
      

      您可以使用表情符号投票,享受!

      【讨论】:

        猜你喜欢
        • 2020-03-19
        • 2021-05-03
        • 1970-01-01
        • 2021-04-09
        • 2021-10-07
        • 2021-03-29
        • 2021-10-20
        • 2021-05-25
        • 1970-01-01
        相关资源
        最近更新 更多