【问题标题】:Create DM to user and wait for response为用户创建 DM 并等待响应
【发布时间】:2021-06-14 02:57:45
【问题描述】:

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

【问题讨论】:

标签: python discord.py


【解决方案1】:

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

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多