问题
i'm doing a discord bot (python 3.8.6).
My function on_ready(): is functional, same for my function "say_hello"
But i don't know why, discord never detects 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)
I don't understand this error, and if someone had this error, ty for help :)
回答1:
discord.py
v1.5 introduces intents
An intent basically allows a bot to subscribe into specific buckets of events.
In order to be able to get server data you need to:
Enable Server Member intents in your application
And Implement
discord.Intents
at the beginning of your code.
import discord
intents = discord.Intents.all()
bot = discord.Client(intents=intents)
# or
from discord.ext import commands
bot = commands.Bot(command_prefix = ".", intents=intents)
For more information, read about Intents | documentation
回答2:
You are trying to send into a undefined channel. You can use discord.utils.get to obtain the channel for the member.guild
object.
Keep in mind you have to replace WELCOME_CHANNEL_NAME
with the target channel.
@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))
channel = discord.utils.get(member.guild.channels, name='WELCOME_CHANNEL_NAME')
print("please")
await channel.send(embed=embed)
来源:https://stackoverflow.com/questions/64425548/my-function-on-member-joinmember-is-never-called