discord.py on_member_join 事件未触发

时间:2021-04-05 01:40:34

标签: python discord discord.py

我正在尝试触发 on_member_join 事件,但当有人加入时它不会触发。我也试图给某人一个加入的角色,但我几乎知道如何做到这一点。我只是不明白为什么这个事件没有在加入时触发。它正在工作,但它停止了。

bot = commands.Bot(command_prefix="!")



player = {}

# Events

@bot.event
async def on_ready():
     print("Bloody Admin is online:")
     await bot.change_presence(status=discord.Status.online, activity=discord.Game("Prefix: !"))
     
     
@bot.event
async def on_member_join(member):
     print("Joined")
    
@bot.event
async def on_member_remove(member):
     await member.create_dm()
     await member.send("I guess I watched you too hard, sorry to see you leave :(")
     

@bot.event
async def on_command_error(ctx, error):
     await ctx.send(error)

我什至尝试将其更改为客户端事件

bot = commands.Bot(command_prefix="!")

client = discord.Client()

player = {}

# Events

@bot.event
async def on_ready():
     print("Bloody Admin is online:")
     await bot.change_presence(status=discord.Status.online, activity=discord.Game("Prefix: !"))
     
     
@client.event
async def on_member_join(member):
     print("Joined")
    
@client.event
async def on_member_remove(member):
     await member.create_dm()
     await member.send("I guess I watched you too hard, sorry to see you leave :(")
     

@bot.event
async def on_command_error(ctx, error):
     await ctx.send(error)

任何帮助都会很棒。谢谢。

1 个答案:

答案 0 :(得分:0)

看起来您缺少意图。

确保在 Discord Developer Portal 中为您的应用开启所有必要的功能。

要将它们实现到您的代码中,您可以使用以下内容:

intents = discord.Intents.all() # Imports all the Intents
client = commands.Bot(command_prefix="YourPrefix", intents=intents)