python - Discord 'on_member_join' 功能不工作

标签 python discord.py

我的 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('*************************')

它正在终端上打印“bot is ready”,所以 bot 正在工作。但是没有检测到成员离开或加入请帮忙。

最佳答案

你可能正在使用 discord python 1.5.0 或更高版本,这是一个常见的错误,你只需要 Intents . 如果出现错误,您应该阅读它,它会将您重定向到 Discord 开发门户中的机器人,在那里您可以激活特权网关意图 check this out

并将其添加到您的代码中

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix='.', intents=intents)

关于python - Discord 'on_member_join' 功能不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64348389/

相关文章:

python - YAML - 转储没有类型/标签的嵌套对象

python - Cogs - 在父目录中查找 (Discord.py)

python - 我得到一个 ClientException : ffmpeg not found error when in discord. py

python-3.x - Discord Bot 不响应命令

python - 第一次完成后取消两个异步协程

python - 使用 pyproject.toml 进行 `` pip install -e .`` 构建 cython 扩展

Python Pandas 逐行条件计算

WebSocket 消息中的 JavaScript 双反斜杠

python - Numpy:将 RGB 平面数组转换为矩阵

python - 有没有办法在我的论点中包含空格?