Discord reaction_add 在私信频道中不起作用

时间:2021-01-27 21:43:22

标签: discord discord.py

我已经解决了这个问题好几天了,这是最后一根稻草。

Reaction_add 仅在我在服务器“常规”频道中执行 !on_message 时才有效,如果我直接向机器人发送消息,则它不会执行任何操作。不过,有趣的是,如果我先直接向机器人发送消息,然后在服务器通用频道中输入 !on_message,机器人会在通用频道和直接消息中做出反应。

TimeoutError 之后,我在直接消息中不受欢迎。

这是直接来自 discord.py 文档的代码,我将 Bot 用作 Client

@bot.command(pass_context=True)
async def on_message(ctx):
    channel = ctx.channel
    await ctx.send('Send me that ? reaction, mate')

    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) == '?'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
    except asyncio.TimeoutError:
        await channel.send('?')
    else:
        await channel.send('?')

有趣的是,wait_for(message, ...) 消息在任何地方都能正常工作。

尝试添加此内容,但仍然没有运气。

intents = discord.Intents.default()
intents.dm_reactions = True

bot = commands.Bot(command_prefix=PREFIX, description=DESCRIPTION, intents=intents)

2 个答案:

答案 0 :(得分:1)

这是因为 on_message 是一个机器人事件,这意味着它不需要作为命令调用,您可以使用 () 调用该命令,但在您的情况下,您正在尝试使用命令作为事件。

这是一个活动

@bot.event
async def on_message(message):
    channel = message.channel
    await message.channel.send('Send me that ? reaction, mate')

    def check(reaction, user):
        return user == message.author and str(reaction.emoji) == '?'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
    except asyncio.TimeoutError:
        await message.channel.send('?')
    else:
        await message.channel.send('?')

这是一个命令,一个命令需要用一个函数来调用,在这种情况下,它会是你的前缀+拇指!thumbs希望这两个都帮助。

@bot.command()
async def thumbs(ctx):
    channel = ctx.channel
    await ctx.send('Send me that ? reaction, mate')

    def check(reaction, user):
        return user == ctx.author and str(reaction.emoji) == '?'

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
    except asyncio.TimeoutError:
        await ctx.send('?')
    else:
        await ctx.send('?')

答案 1 :(得分:1)

我添加了 intents = discord.Intents.all(),这似乎可以解决问题,但效率不高,因为我可能不需要所有特权意图。

对问题的输入会有所帮助。