【问题标题】:Discord Bot Won't @ PeopleDiscord Bot不会@People
【发布时间】:2021-02-18 11:04:03
【问题描述】:

我一直在制作一个机器人,它将对消息做出反应的人添加到数组中,然后在达到目标后将@的每个人都添加到数组中。我已经让它发出应该@每个人的消息,但它只显示文本而不是实际通知人们。 “Names”是它收集的列表,“send_out”应该对其进行格式化。

@client.event
async def on_raw_reaction_add(payload):
  if payload.message_id == messageid and payload.member.bot == False:
    if str(payload.emoji.name) == "????":
      name = str(payload.member.name + "#" + payload.member.discriminator)
      global count
      count += 1
      global names
      names.append(name)
      print (names)
      if (count == goal_actual):
        print("Goal has been reached.")
        channel = client.get_channel(channel_id)
        await channel.send("We now have " + str(goal_actual) + " for " + game_actual + "!")
        print(channel)
        global send_out
        for x in names:
          send_out += ("@" + x +"  ")
        await channel.send(send_out)
        send_out = []
      else:
        print("Detected reaction from " + name + ". There are is now " , count ,  " people ready.")
  

【问题讨论】:

    标签: python discord


    【解决方案1】:

    最好使用payload给你的member对象

    Here (discord.py docs) 我们可以看到discord.on_raw_reaction_add(payload) 给出了一个RawReactionActionEvent 对象。

    RawReactionActionEvent也有一个member对象,是一个普通的member object,这个有一个属性member.mention

    你可以用它来标记人

    @client.event
    async def on_raw_reaction_add(payload):
      if payload.message_id == messageid and payload.member.bot == False:
        if str(payload.emoji.name) == "?":
          global count
          count += 1
          global names
          names.append(payload.member)
          print (names)
          if (count == goal_actual):
            print("Goal has been reached.")
            channel = client.get_channel(channel_id)
            await channel.send("We now have " + str(goal_actual) + " for " + game_actual + "!")
            print(channel)
            global send_out
            for member in names:
              send_out += (member.mention)
            await channel.send(send_out)
            send_out = []
          else:
            print("Detected reaction from " + name + ". There are is now " , count ,  " people ready.")
    

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 2022-10-21
      • 2021-12-02
      • 2020-12-21
      • 2021-10-21
      • 2021-05-29
      • 2022-07-05
      • 2021-06-15
      • 2021-01-09
      相关资源
      最近更新 更多