【发布时间】:2021-06-14 02:57:45
【问题描述】:
我想使用 discord.py 为特定用户创建一个 DM,当他们回复时,它会在 DM 中将他们的消息发回给我。我该怎么做?我试图搜索,但找不到任何东西。
【问题讨论】:
-
欢迎来到 StackOverflow。请包括您的代码、方法和您面临的错误。你也可以看看how to ask a good question
标签: python discord.py
我想使用 discord.py 为特定用户创建一个 DM,当他们回复时,它会在 DM 中将他们的消息发回给我。我该怎么做?我试图搜索,但找不到任何东西。
【问题讨论】:
标签: python discord.py
你可以使用wait_for来做到这一点
@bot.command()
async def dm_user(ctx, member: discord.Member):
try:
await member.send('Hi yo have 30 seconds to respond')
except discord.HTTPException:
await ctx.send('unable to message')
else:
try:
msg = await bot.wait_for('message', check = lambda x: x.channel == member.dm_channel and x.author == member, timeout=30)
except asyncio.TimeoutError:
await ctx.send('timed out')
finally:
await ctx.author.send(msg.content)
【讨论】: