【问题标题】:Specific command executed by certain user - discord.py特定用户执行的特定命令 - discord.py
【发布时间】:2021-12-31 21:28:55
【问题描述】:

我在 Replit 中使用 discord.py 来制作我的 Discord Bot。我想创建一个在两条语句为真时执行的命令。首先是它是正确的命令,其次是输入它的人是我,制造者。如何制作这段代码?

这里是代码链接 - https://replit.com/@DerekWeber/DiscordBot#main.py

请帮帮我...

【问题讨论】:

  • 你在找this
  • 我编辑了问题,添加了代码链接。
  • 不要添加指向您的代码的链接,而是添加您遇到问题的代码部分,谢谢。
  • 我想添加一个在特定用户键入命令时运行的命令。我不知道如何实现

标签: python discord.py


【解决方案1】:

您可以使用message.author.id 获取用户的 Discord ID,例如:

#Import discord and other modules.

@client.event
async def on_message(message):
    if message.author.id == yourdiscordid:
        print("It's me!")
        
    else:
        print("It's you, not me!")

#Run the bot.

yourdiscordid 替换为您的Discord ID(不是您的机器人),on_message() 函数的message 参数是该函数的第一个 参数。

如何获取您的 Discord ID:右键单击您的个人资料(在 Discord 中),然后从菜单中单击“复制 ID”。

查看this了解如何使用message.author.id

【讨论】:

    猜你喜欢
    • 2019-04-04
    • 2010-11-08
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 2020-09-13
    • 2012-03-20
    • 1970-01-01
    相关资源
    最近更新 更多