我的 on_member_join 似乎不起作用。我希望我的机器人说出加入服务器的成员的姓名,但它无法检测是否有人加入或离开。
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print("bot is ready ")
@client.event
async def on_member_join(member):
print(f'{member.name} has joined this server')
@client.event
async def on_member_remove(member):
print(f'{member}was removed')
client.run('*************************')
它正在终端上打印“机器人已准备好”,因此机器人正在工作。但没有检测到成员离开或加入请帮忙。
您可能使用的是discord python 1.5.0或更高版本,这是一个常见错误,您只需要Intents https://discordpy.readthedocs.io/en/latest/intents.html。
如果出现错误,您应该阅读它,它会将您重定向到不和谐开发门户中的机器人,您可以在那里激活特权网关意图看一下这个 https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents
并将其添加到您的代码中
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='.', intents=intents)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)