为用户创建 DM 并等待响应

时间:2021-03-16 19:03:05

标签: python discord.py

我想使用 discord.py 为特定用户创建一个 DM,当他们响应时,它会在 DM 中将他们的消息发送回我。我该怎么做?我试图搜索,但找不到任何东西。

1 个答案:

答案 0 :(得分:0)

您可以使用 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)

参考:

相关问题