python - 成员加入上的 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)
但是代码什么也没做。
提前致谢
解决方案
由于最近的更新,要接收GUILD_MEMBERS
意图(其中包含GUILD_MEMBER_ADD
事件),您需要启用它。为此:
- 访问discord.com/developers/applications
- 单击您希望启用特权意图的机器人
- 导航到左侧的“Bot”选项卡
- 滚动到特权网关意图部分
- 启用您想要的意图(在本例中为 SERVER MEMBERS INTENT)
推荐阅读
- c++ - (C++) 读取矩阵文件的最快方式(任意大小)
- intersystems-iris - $Increment 和 $Sequence 函数有什么区别?
- parquet - 如何追加到镶木地板文件以及它如何影响分区?
- android - 滚动屏幕直到列表到达顶部
- docker - docker compose v3 的部署资源的行为限制了“cpus”参数设置(是绝对数量还是可用核心的百分比)
- javascript - 多个车把文件未读取 css 文件
- python - 在给定唯一列值的情况下,熊猫数据框如何删除以小于数字的行长为条件的行?
- python - 如何解析和保留文本格式(Python-Docx)?
- php - php 方法不会截断文本文件
- python - 如何组合/联合两个单独的 numpy 高斯集?