python - 我的函数 on_member_join(member) 从未被调用
问题描述
我正在做一个不和谐的机器人(python 3.8.6)。
我的功能 on_ready(): 是功能性的,与我的功能“say_hello”相同
但我不知道为什么,discord 从不检测 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)
我不明白这个错误,如果有人有这个错误,请帮忙:)
解决方案
discord.py
v1.5 引入意图
意图基本上允许机器人订阅特定的事件桶。
为了能够获取服务器数据,您需要:
在您的应用程序中启用服务器成员意图
并
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)
推荐阅读
- ruby-on-rails - 如何覆盖 CanCanCan 中的默认方法
- flutter - “目前不支持flutter web”
- c++ - C++:C2280 错误:无法将矩阵条目设置为给定值
- python-3.x - 在 Pandas Python 中连接帧时的日期格式更改
- instagram - Instagram 禁止我的服务器 IP 地址使用 __a=1 api
- dhall - 将不同模式与联合值相关联的惯用方式是什么?
- angular - Angular (8) - Foreach 循环调用 subscribe 和 ForkJoin 他们(见描述)
- javascript - 生命之虫游戏
- vb.net - Vb.net Itextsharp OCR 检查
- function - OCaml 幂函数