【问题标题】:on message event is not triggering消息事件未触发
【发布时间】:2021-08-04 21:59:59
【问题描述】:
@client.event
async def on_message(message):
    if message.channel.id == 872448587571789834:
        data = message.content.split(" ")
        user = re.sub("\D", "", data[0])

        user_object = client.get_user(int(user)) or await client.fetch_user(int(user))
        user = user_object
        await user_object.send("Hey, thanks for up-voting me on top.gg, here take 10,000 coins and a special role as an award ????")
        #voted = discord.utils.get(message.guild.roles, name="???? Voted for Legend Moderation????")
        await open_account(user_object)

        users = await get_bank_data()

        users[str(user.id)]["wallet"] += 10000

        with open("bank.json", "w") as f:
            json.dump(users, f, indent=4)

这里的代码检查是否在该特定频道中发送了一条消息并获取其第一个用户名,以便它可以 dm 该用户并给他钱 整个事件甚至都不起作用我没有收到任何错误

【问题讨论】:

  • 你确定它没有运行吗?如果你在if 之前打印一些东西怎么办?
  • 甚至不打印
  • 你有多个on_message事件吗?
  • 是的,我有很多
  • 你只能有一个 on_message 事件,否则,最后一个会覆盖以上所有事件。

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


【解决方案1】:

如果您在发送消息时没有收到任何错误,可能是因为在您的机器人设置中您没有启用 SERVER MEMBERS INTENT

在门户中启用它后,您需要添加一些代码。

查找更多信息here

希望这个回答对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 2013-10-10
    • 2016-12-19
    • 1970-01-01
    相关资源
    最近更新 更多