Discord机器人可以';无法检测消息作者python

Discord机器人可以';无法检测消息作者python,python,discord,discord.py,Python,Discord,Discord.py,当某个用户发送消息时,Discord bot不允许我触发命令 import discord from discord.ext.commands import Bot from discord.ext import commands import asyncio Client = discord.Client() client = commands.Bot(command_prefix = "!") @client.event async def on_message(message):

当某个用户发送消息时,Discord bot不允许我触发命令

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio

Client = discord.Client()
client = commands.Bot(command_prefix = "!")


@client.event
async def on_message(message): 
    if message.author == "exampleuser#0000":
        await client.send_message(message.channel, "success")

client.run("insert token here")
你可以试试看

@client.event
async def on_message(message): 
    if message.author.id == "author ID":
        await client.send_message(message.channel, "success") 
要查找个人id,请首先在discord(设置、外观、高级)中启用开发人员模式。之后,在discord中右键单击他们的名字,然后单击复制Id。然后,将Id粘贴到作者Id中。希望这有帮助

如中所述,
message.author
是一个,而不是一个字符串。将成员与字符串进行比较总是会导致
False


由于
成员
是的子类,因此可以使用来标识作者:

@client.event
async def on_message(message): 
    if message.author.id == "some_id":
        await client.send_message(message.channel, "success")
描述如何查找用户ID。概括起来:

  • 在设置->外观->高级下启用开发人员模式
  • 右键单击用户并点击“复制ID”

  • 欢迎来到stackoverflow!为了让我们帮助您,您需要为我们提供一个服务。