本文介绍了不和谐的"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('*************************')

正在打印机器人已准备就绪".在终端上,因此机器人可以正常工作.但是并没有检测到成员离开或加入pls的帮助.

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开发人员门户中的bot,在那里您可以激活特权网关意图查看此

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)

这篇关于不和谐的"on_member_join"功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:19