Discord 机器人无法检测到消息作者 python

Discord bot can't detect message author python

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 中启用开发者模式(设置、外观、高级)。之后,在不和谐中右键单击他们的名字,然后单击复制 ID。然后,将 ID 粘贴到作者 ID 中。希望这对您有所帮助!

the documentation, message.author is a Member object所述,不是字符串。将成员与字符串进行比较将始终得到 False.


由于MemberUser, you can use the id attribute的子类,要识别作者:

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

This article 介绍了如何查找用户 ID。总结一下:

  1. 在设置 -> 外观 -> 高级下启用开发者模式
  2. 右键单击用户并点击 "copy ID"