首页 > 解决方案 > Discord.py:on_member_join 突然停止工作

问题描述

我正在尝试以下代码:

@bot.event
async def on_member_join(member):
    print("works")
    for channel in member.guild.text_channels:
        if channel.name == 'general':
            await channel.send("Welcome to " + member.guild.name + ", " + member + "!")

我之前的on_member_join活动运行良好,但由于某种原因它不再运行了。我尝试更新到 discord.py 1.5。任何帮助将不胜感激。

我没有收到任何错误。

标签: pythondiscord.py

解决方案


discord.py1.5.0 现在支持不和谐 API 的特权网关意图。为了能够利用服务器数据,您需要:

在此处输入图像描述

intents = Intents.all()

#If you use commands.Bot()
bot = commands.Bot(command_prefix="!", intents=intents)

#If you use discord.Client()
client = discord.Client(intents=intents)

推荐阅读