Discord.py DM命令(发送和接收DM)
我对python非常陌生,我想制作一个discord bot来发送一个dm,当其他用户收到dm时,他们会回复,代码所有者或服务器管理员将能够看到它所说的内容 以下是我迄今为止为dm编写的代码:Discord.py DM命令(发送和接收DM),discord.py,bots,dm,Discord.py,Bots,Dm,我对python非常陌生,我想制作一个discord bot来发送一个dm,当其他用户收到dm时,他们会回复,代码所有者或服务器管理员将能够看到它所说的内容 以下是我迄今为止为dm编写的代码: @client.command() async def dm(ctx, user: discord.User, *, message): await user.send(message) 如何使其能够查看用户对bot的回复?为此,您可以使用客户端。使用检查()等待(),因此在等待用户。发送(消息
@client.command()
async def dm(ctx, user: discord.User, *, message):
await user.send(message)
如何使其能够查看用户对bot的回复?为此,您可以使用
客户端。使用检查()
等待()
,因此在等待用户。发送(消息)
之后添加此项:
如果这是您的dm
功能中的,则为所有
参考资料:
谢谢你的回答!我只要把凹痕修好,我就可以走了!
def check(msg):
return msg.author == user and isinstance(msg.channel, discord.DMChannel)#check for what the answer must be, here the author has to be the same and it has to be in a DM Channel
try:
answer = await client.wait_for("message", check=check, timeout=600.0)#timeout in seconds, optional
await ctx.send(answer.content)
except asyncio.TimeoutError:
await author.send("Your answer time is up.")#do stuff here when the time runs out