我的函数on_member_join(member)从未被调用

时间:2020-10-19 10:31:25

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

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

我的函数on_ready():功能正常,与我的函数“ say_hello”相同

但是我不知道为什么,不和谐永远不会检测到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)

我不了解此错误,如果有人遇到此错误,请联系我们以寻求帮助:)

2 个答案:

答案 0 :(得分:1)

discord.py v1.5 介绍了意图

意图基本上可以使漫游器订阅特定的事件桶。

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

  • 在您的application中启用服务器成员意图 enter image description here

  • 并在代码的开头实施discord.Intents

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 | documentation

答案 1 :(得分:0)

您正尝试发送到未定义的频道。您可以使用discord.utils.get获取member.guild对象的频道。

请记住,您必须用目标频道替换WELCOME_CHANNEL_NAME

@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)