我对 python 很陌生,嗯,我想制作一个发送 dm 的不和谐机器人,当其他用户收到 dm 时,他们会回复,代码的所有者或服务器的管理员将能够看看它说什么!
到目前为止,这是我的 dm 代码:
@client.command()
async def dm(ctx, user: discord.User, *, message):
await user.send(message)
我该如何做才能看到用户对机器人的回复?
我对 python 很陌生,嗯,我想制作一个发送 dm 的不和谐机器人,当其他用户收到 dm 时,他们会回复,代码的所有者或服务器的管理员将能够看看它说什么!
到目前为止,这是我的 dm 代码:
@client.command()
async def dm(ctx, user: discord.User, *, message):
await user.send(message)
我该如何做才能看到用户对机器人的回复?
为此,您可以使用client.wait_for()
with check()
,因此在 之后添加await user.send(message)
:
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
如果这在你的dm
功能中。
参考: