Discord #39;on_member_join#39; function not working(Discord on_member_join 功能不起作用)
问题描述
我的 on_member_join 似乎不起作用.我希望我的机器人说出加入服务器的成员的姓名,但它不检测是否有人加入或离开.
My on_member_join doesnt seem to work. I wanted my bot to say out the names of the members that joined the sever but it doesnt detect if someone has joined or left.
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('*************************')
它正在打印bot is ready";在终端上,因此机器人正在工作.但是没有检测到成员离开或加入请帮助.
It is printing "bot is ready" on the terminal so the bot is working. But isn't detecting members leaving or joining pls help.
推荐答案
你使用的可能是discord python 1.5.0或以上版本,这是一个常见的错误,你只需要意图.如果有错误,您应该阅读它,它会将您重定向到 discord 开发门户中的机器人,在那里您可以激活特权网关意图 看看这个
You're probably using discord python 1.5.0 or above, it's a common error, you just need Intents. If there's a error, you are supposed to read it, it will redirect you to your bot in the discord dev portal, there you can activate the privileged gateway intents check this out
并将其添加到您的代码中
And add this to your code
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='.', intents=intents)
这篇关于Discord 'on_member_join' 功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord 'on_member_join' 功能不起作用
基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01