【问题标题】:How do i send a message including a reaction with discord.py我如何发送包含对 discord.py 的反应的消息
【发布时间】:2020-02-28 12:51:15
【问题描述】:

如何发送包含反应的消息? 我希望用户能够使用 !Test 触发命令,并且 Bot 以 test 和红十字作为反应来回复。

我的代码:

@client.command()
async def Test(ctx, message = "test"):

  Message = await ctx.send(apme, "????️‍????")
  await client.add_reaction(Message, emoji="redCross:423541694600970243")```

【问题讨论】:

    标签: python asynchronous discord discord.py


    【解决方案1】:

    这行得通,我不得不做一些挖掘工作,我发现你必须使用unicode 来表示表情符号

    您可以使用相同的概念来制作命令。

    @client.event
    async def on_message(message):
        if message.content == "poll" in message.content:
            mm = await message.channel.send("react to this")
            await mm.add_reaction('\U0001f44d')
     
        await client.process_commands(message) 
    
    
    @client.command()
    async def  poll(ctx,*,polltext):
        mm = await ctx.send(f'{polltext}')
        await mm.add_reaction('\U0001f44d')
        await mm.add_reaction('\U0001f44e')
    
    

    【讨论】:

      【解决方案2】:

      我很多时候喜欢走捷径,所以我个人会这样写:

      import discord
      from discord.ext.commands import Bot
      from discord.ext import commands
      
      Client = discord.Client() # Initialise Client 
      client = commands.Bot(command_prefix = "?") # Initialise client bot
      
      @client.event
      async def on_ready():
          print("ready")
      
      @client.event
      async def on_message(message):
          if message.content == "!test" in message.content:
              await message.channel.send("test :x:")
      client.run("input token")
      

      叫我懒惰,但它有效 XD。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-11
        • 1970-01-01
        • 1970-01-01
        • 2020-03-03
        • 2021-06-15
        • 1970-01-01
        • 1970-01-01
        • 2020-05-07
        相关资源
        最近更新 更多