【问题标题】:How to DM a discord user with user input from discord.py [duplicate]如何使用来自 discord.py 的用户输入来 DM 不和谐用户 [重复]
【发布时间】:2022-01-02 21:52:53
【问题描述】:
def check2(msg):
    return msg.author == ctx.author and msg.channel == ctx.channel

msg = await client.wait_for("message", check=check2, timeout=30)
member = ???
await member.send("test")

当它要求用户输入时,我会说,例如,@Bob。鉴于我提到了他们,我该如何将其设为 DM @Bob?

【问题讨论】:

  • This 看起来正是您所需要的。

标签: python discord.py bots


【解决方案1】:

您可以使用属性 mentions,它会为您提供消息提及的用户列表

如果你想提及多个用户:-

msg = await client.wait_for("message", check=check2, timeout=30)
mentions = msg.mentions
for users in mentions:
    await user.send("test")

或者,如果您只想发送一个用户,那么:-

msg = await client.wait_for("message", check=check2, timeout=30)
mentions = msg.mentions
user = msg.mentions[0]
await user.send("test")

【讨论】:

    猜你喜欢
    • 2017-09-18
    • 1970-01-01
    • 2015-06-03
    • 2020-04-11
    • 1970-01-01
    • 2015-11-10
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多