Discord bot中的用户专有命令

时间:2020-09-08 02:32:56

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

我正在用Python做一个Discord机器人,我想创建一个只能使用的命令。这是我尝试的示例代码,但是没有用:

    #replace MY_USER_ID with user ID number.
    if message.content.startswith('$hello'):
        if message.author == "<@MY_USER_ID>":
            await message.channel.send('Hello creator!')
        else:
            await message.channel.send('Hello!')

使用Python 3.8.5和discord.py 1.4.1。

1 个答案:

答案 0 :(得分:1)

使用message.author.id获取作者的ID,并将您的ID作为int而不是str传递。

@bot.event
async def on_message(message):
    if message.content.startswith('$hello'):
        if message.author.id == 1234567890:
            await message.channel.send('Hello creator!')
        else:
            await message.channel.send('Hello!')