【问题标题】:Attempting to get a discord bot to react to all messages within a certain channel试图让不和谐机器人对某个频道内的所有消息做出反应
【发布时间】:2020-10-03 15:08:55
【问题描述】:

这个脚本不是我的。该脚本是有效的,但它只适用于一个用户。我希望它对任何用户在某个频道内发送的所有消息做出反应。我认为问题出在 message.author.id 事情上,我尝试完全删除该行,但它最终破坏了整个事情并且它不会启动不和谐机器人。非常感谢任何帮助。

from discord.ext        import commands
from discord.ext.commands    import Bot
import asyncio

bot = commands.Bot(command_prefix = "$")

@bot.event
async def on_ready():
    print ("welcome_msg")

async def react(message):
    custom_emojis = [
    ":like:",
    ":emoji:",
    ":emoji:"
    ]
    guild_emoji_names = [str(guild_emoji) for guild_emoji in message.guild.emojis]
    for emoji in custom_emojis:
        if emoji in guild_emoji_names:
            await message.add_reaction(emoji)

@bot.event
async def on_message(message):
    if message.channel.id == 721485450790830111 and \
        message.author.id == 721483699719241748:
            await react(message)```

【问题讨论】:

  • 如果您将条件更改为if message.channel.id == 721485450790830111:,它应该可以工作。您可能只是格式错误。

标签: python discord.py discord.py-rewrite


【解决方案1】:

自定义服务器表情符号不能只按名称调用。您需要使用某个字符串来调用它们: <:emoji_name:emoji_id>

这一切都在this thread(或github问题here)中有详细说明。

这意味着您需要重写您的 custom_emojis 列表,使其由类似格式的字符串组成。

【讨论】:

  • 但是脚本有效,但它只适用于一个人。我希望它适用于某个频道中的所有人和消息。但是,它只有在我将用户 ID 放入脚本时才有效。
  • 那么@Patrick Haugh 的回答应该会有所帮助。
猜你喜欢
  • 2020-09-03
  • 2021-06-25
  • 1970-01-01
  • 2020-11-20
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 2020-12-06
  • 1970-01-01
相关资源
最近更新 更多