問題描述
我的 on_member_join 似乎不起作用.我希望我的機(jī)器人說出加入服務(wù)器的成員的姓名,但它不檢測是否有人加入或離開.
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";在終端上,因此機(jī)器人正在工作.但是沒有檢測到成員離開或加入請幫助.
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或以上版本,這是一個(gè)常見的錯(cuò)誤,你只需要意圖.如果有錯(cuò)誤,您應(yīng)該閱讀它,它會將您重定向到 discord 開發(fā)門戶中的機(jī)器人,在那里您可以激活特權(quán)網(wǎng)關(guān)意圖 看看這個(gè)
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)
這篇關(guān)于Discord 'on_member_join' 功能不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!