我尝试了一些代码,但对于等待消息不起作用,所以我想知道如果用户使用discord.py在 channel 中发送命令,如何在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
为了这。您可以编写自定义检查
来查看它是否是 DM channel 。该检查是一个函数,如果您的函数应该停止等待,则返回 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
关于python - 如果用户在 channel 中发送命令,则等待 DM 中的消息问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64593691/