【问题标题】:Discord bot can't detect message author pythonDiscord bot无法检测到消息作者python
【发布时间】:2018-06-28 06:10:47
【问题描述】:

当某个用户发送消息时,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")

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

你可以试试

@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 中。希望这会有所帮助!

【讨论】:

    【解决方案2】:

    the documentation 中所述,message.authorMember object,而不是字符串。将成员与字符串进行比较总是会得到False


    由于MemberUser 的子类,您可以使用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. 右键单击用户并点击“复制 ID”

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2021-03-02
      • 2022-11-17
      • 2021-03-27
      • 2022-10-14
      • 2020-11-22
      • 2021-10-30
      • 2022-12-09
      • 2019-11-23
      相关资源
      最近更新 更多