Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 试图让discord bot对某个通道内的所有消息作出反应_Python_Discord.py_Discord.py Rewrite - Fatal编程技术网

Python 试图让discord bot对某个通道内的所有消息作出反应

Python 试图让discord bot对某个通道内的所有消息作出反应,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,这个脚本不是我的。该脚本功能正常,但只对一个用户有效。我希望它对任何用户在某个通道内发送的所有消息做出反应。我想问题出在message.author.id这件事上,我试着全力以赴删除这条线,但它最终只是破坏了整个事情,它无法启动discord机器人。非常感谢您的帮助 from discord.ext import commands from discord.ext.commands import Bot import asyncio bot = commands.Bot(c

这个脚本不是我的。该脚本功能正常,但只对一个用户有效。我希望它对任何用户在某个通道内发送的所有消息做出反应。我想问题出在message.author.id这件事上,我试着全力以赴删除这条线,但它最终只是破坏了整个事情,它无法启动discord机器人。非常感谢您的帮助

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)```

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

这些都在(或github问题)中有详细说明


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

如果您将该条件更改为
If message.channel.id==721485450790830111:
它应该可以工作。您可能只是有一些格式错误。但是脚本可以工作,但它只能在一个人身上工作。我希望它能在某个频道的所有人和消息上工作。但是,只有在脚本中加入用户ID时,它才会起作用。那么@Patrick Haugh的答案应该会有帮助。