【问题标题】:How to get discord.py bot to DM a specific user如何让 discord.py 机器人 DM 特定用户
【发布时间】:2018-05-10 01:24:59
【问题描述】:

我已经搜索了很多这个答案,但我没有找到它。我想使用一个建议命令,每当有人用它来建议一个想法时,它就会给我发私信,而且只发给我。

【问题讨论】:

  • 欢迎来到Stack Overflow。预计问题符合某些标准。这些在我强烈建议您阅读的How to Ask 页面中进行了描述。此外,我们预计您已经付出了一定程度的努力。这通常是通过向我们展示您正在处理的代码并向我们提供您尝试过的事情和观察到的结果的描述来完成的。如果代码块较大,将其简化为 minimal reproducible example 有助于我们更快地理解问题。

标签: python python-3.x discord.py


【解决方案1】:
@client.event
async def on_message(message):
    if message.content.startswith("#whatever you want it to be")
        await client.send_message(message.author, "#The message")

用你想要的词替换带有标签的东西。例如:#whatever you want it to be "!help"。 #消息可能是“命令是...”。

【讨论】:

  • 您能详细说明一下吗?
  • 用你想要的词替换带有标签的东西。例如:#whatever you want it to be "!help"。 #消息可能是“命令是...”
【解决方案2】:

您必须使用send_message 方法。在此之前,你必须找到与自己对应的User

@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    # can be cached...
    me = await client.get_user_info('MY_SNOWFLAKE_ID')
    await client.send_message(me, "Hello!")

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 2021-11-14
    • 2023-03-31
    • 2021-12-03
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2021-10-22
    • 2021-06-12
    相关资源
    最近更新 更多