簡體   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