首页 > 解决方案 > 如何让 Discord 机器人(使用 discord.py)测试 dms 中的响应?

问题描述

我正在开发一个用于验证目的的项目,但我无法找到任何指向您如何检查响应及其有效性以及它是否是对机器人问题的响应的来源。任何建议或来源将不胜感激。

标签: pythonauthenticationdiscorddiscord.py

解决方案


您可以使用该on_message事件或wait_for

@bot.event
async def on_message(message):
    # Checking if the type of the channel is `discord.DMChannel`
    if isinstance(message.channel, discord.DMChannel):
        await message.channel.send("Responding in dm's")
@bot.command()
async def command(ctx):
    def check(message):
        # Checking if the author of the message is the same as the author of the command
        # And if the channel is a `discord.DMChannel` instance
        return message.author == ctx.author and isinstance(message.channel, discord.DMChannel)

    await ctx.author.send("Waiting for a reply in dm's")  
    message = await bot.wait_for('message', check=check)
    await ctx.author.send("Responding in dm's")

参考:


推荐阅读