首页 > 解决方案 > 成员加入上的 discord.py 不起作用或返回错误消息

问题描述

我有这个代码,但它什么也没做。

intents = discord.Intents.default()
intents.members = True

client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='!', description="Hey there, I'm Robo!")
@client.event
async def on_member_join(member):
    print(f'{member} has joined the server.')
    channel = client.get_channel(ChannelId) # i enter my channel id
    embed=discord.Embed(title="Welcome", description="Welcome to the server, " + member, color=999)
    embed.set_footer(text="A footer")
    await channel.send(embed=embed)

但是代码什么也没做。

提前致谢

标签: pythonpython-3.xdiscorddiscord.py

解决方案


由于最近的更新,要接收GUILD_MEMBERS意图(其中包含GUILD_MEMBER_ADD事件),您需要启用它。为此:

  1. 访问discord.com/developers/applications
  2. 单击您希望启用特权意图的机器人
  3. 导航到左侧的“Bot”选项卡
  4. 滚动到特权网关意图部分
  5. 启用您想要的意图(在本例中为 SERVER MEMBERS INTENT)

推荐阅读