繁体   English   中英

来自 discord.py 的 wait_for() 在 dm 中不起作用

[英]wait_for() from discord.py don't work in dm

此代码适用于服务器频道,但不适用于用户的私人消息。 是否有私人消息的替代功能?

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$thumb'):
        channel = message.channel
        await channel.send('Send me that 👍 reaction, mate')

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

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=10.0, check=check)
        except asyncio.TimeoutError:
            await channel.send('👎')
        else:
            await channel.send('👍')

我发现了一些与我类似的问题并重新编写了代码,但没有帮助:

discord.py wait_for('reaction_add') 与直接消息的功能不同

DM 中的 Discord.py Bot 反应

import discord

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

client = discord.Client()

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$thumb'):
        
        msg = await message.channel.send(f'Hi {message.author.mention}')
        await msg.add_reaction('✅')

        def check(reaction, user):
            print(user.id, message.author.id)
            return reaction.message.id == msg.id and user.id == message.author.id and str(reaction.emoji) == '✅'

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=30.0, check=check)
        except asyncio.TimeoutError:
            pass
        else:
            await message.channel.send('success')

client.run(token)

只是制作一个intents变量不会让你的机器人使用它。

client = discord.Client(intents=intents)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM