python - 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。任何帮助将不胜感激。
我没有收到任何错误。
解决方案
discord.py
1.5.0 现在支持不和谐 API 的特权网关意图。为了能够利用服务器数据,您需要:
- 启用
Presence Intent
并Server Members Intent
在您的不和谐应用程序中:
discord.Intents
在代码开头使用:
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)
推荐阅读
- jquery-ui - GAS PropertiesService 保存和返回排序顺序
- asp.net - 通过链接或按钮将值从 ASPX 页面传递到代码后面
- javascript - JSON.parse() 返回 [object Object] (Node.Js)
- javascript - 出现错误:预检响应中的 Access-Control-Allow-Headers
- delphi - 是否有可能找到谁建立了一个 exe 文件?
- java - 我们是否应该像在 .Net 中那样在 java 中创建 Java 源代码和 Junit 测试作为不同的项目?
- php - 使用来自 github 的 laravel 运行克隆 PHP 项目时出错
- python - 如何使用自定义域将 HTTPS 流量强制到灵活的 Google App Engine?
- excel - VBA中的自动填充
- asp.net-mvc - 如何将字节转换为文件 asp.net MVC