不和谐reaction_add在私信频道中不起作用



这几天我一直在排除这个问题,这真是让人忍无可忍。

Reaction_add只工作,如果我做!on_message在服务器'一般'通道,如果我直接消息聊天机器人,它不做任何事情。不过,有趣的是,如果我直接先给bot发消息,然后在服务器通用通道输入!on_message, bot会在通用通道和直接消息中做出反应。

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)

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

这是个事件

@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('👍')

我添加了intents = discord.Intents.all(),这似乎奏效了,尽管效率不高,因为我可能不需要所有的特权意图。

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

最新更新