【问题标题】:On_member_join and on_member_remove events do not workOn_member_join 和 on_member_remove 事件不起作用
【发布时间】:2023-03-12 14:00:01
【问题描述】:

我试图制作一个 Discord 机器人,它可以打印用户加入或离开控制台。但是,它似乎没有触发我的 Bot。这是我的代码:

这是我当前的代码

    import discord 
    from discord.ext import commands
    
    client = commands.Bot(command_prefix='!')
    
    @client.event
    async def on_ready():
      print("Bot is ready")


    @client.event
    async def on_member_join():
      print("{member} hat den Server betreten.")

   ```@client.event
   async def on_member_remove():
      print("{member} hat den Server verlassen.")

  
   client.run('My Token')

有人可以帮帮我吗?

【问题讨论】:

标签: python discord discord.py bots


【解决方案1】:

使用on_member_join 或其他与成员事件相关的事件必须要求启用成员意图。这样可以让这些事件在它们是私有的时运行,并且应该小心使用。

可以从 Discord 开发者门户启用 Intent,从那里您只需确保已在“Bot”类别中的 Intent 中启用 Member。然后,您需要在定义机器人或客户端的部分中定义和使用机器人代码中的意图:

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='your bot prefix', intents=intents)

【讨论】:

    猜你喜欢
    • 2022-10-02
    • 2020-09-19
    • 2021-02-25
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多