如何让 discord.py bot 向特定用户发送 DM

新手上路,请多包涵

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

原文由 OffstageAlmond 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 833
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!")

原文由 greut 发布,翻译遵循 CC BY-SA 3.0 许可协议

@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 be could be “!help”. #The message 可能是“The commands are…”。

原文由 fire21407 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题