首页 > 解决方案 > 我的函数 on_member_join(member) 从未被调用

问题描述

我正在做一个不和谐的机器人(python 3.8.6)。

我的功能 on_ready(): 是功能性的,与我的功能“say_hello”相同

但我不知道为什么,discord 从不检测 on_member_join(member)

bot = commands.Bot(command_prefix =".", description = "yolooooooooooooooooooooooooooooo")

#prints 'logged on' when bot is ready
@bot.event
async def on_ready():
    print('logged on salaud')


@bot.event
async def on_member_join(member):
    embed=discord.Embed(title=f"Welcome To Mafia Server, Be carefully or you will die", color=random.randint(0, 0xFFFFFF))
  
    print("please")
    await channel.send(embed=embed)

我不明白这个错误,如果有人有这个错误,请帮忙:)

标签: pythonpython-3.xdiscorddiscord.py

解决方案


discord.py v1.5 引入意图

意图基本上允许机器人订阅特定的事件桶。

为了能够获取服务器数据,您需要:

import discord

intents = discord.Intents.all()


bot = discord.Client(intents=intents)

# or 

from discord.ext import commands
bot = commands.Bot(command_prefix = ".", intents=intents)


有关更多信息,请阅读Intents | 文件


推荐阅读