如果用户在信道中发送命令,则等待DM中的消息



我尝试了so me代码,但不适用于等待消息,所以我想知道如果用户在使用discord.py.的通道中发送命令,如何在DM中等待消息

更新的

这是最后一个根据公认答案作为示例的代码!

async def command_name(ctx):
await ctx.send("Send a message in DM.")
def check(m):
return m.author == ctx.author and m.guild is None
msg = await client.wait_for('message', check=check)
# Do something after they sent a DM``` 

为此使用内置的wait_for。您可以编写一个自定义check来查看它是否是DM通道。如果函数应该停止等待,则check是一个返回True的函数,如果不应该,则返回False。您只需稍微修改文档中的示例即可获得您想要的结果:

@client.command()
async def command_name(ctx):
await ctx.send("Send a message in DM.")
def check(m):
return m.author == ctx.author and m.guild is None
msg = await client.wait_for('message', check=check)
# Do something after they sent a DM

最新更新