Discord.py (Rewrite) on_member_update not working properly(Discord.py(重写)on_member_update 无法正常工作)
问题描述
我对 discord.py 包的 on_member_update 函数有疑问.我的问题是 on_member_update 函数仅在机器人本身更新(如角色更新)时触发,而不是在其他用户更新时触发(它应该如何工作).这是我的代码的细分:
I have a question about the on_member_update function of the discord.py package. My Issue is that the on_member_update function only triggers when the bot itself is updated (like a role update) and not when an other user is updated (how it's supposed to work). Here is a breakdown of my Code:
import discord
from discord.ext import commands
import sys
TOKEN = 'myToken'
BOT_PREFIX = '!'
Intents = discord.Intents()
Intents.members = True
Intents.presences = True
bot = commands.Bot(command_prefix=BOT_PREFIX, Intents = Intents)
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "
")
@bot.event
async def on_member_update(before, after):
if str(before.status) == "online":
if str(after.status) == "offline":
print("{} has gone {}.".format(after.name,after.status))
else:
print("lol")
@bot.command(pass_context=True)
async def stop(ctx):
await ctx.author.send("bot stopped")
sys.exit(0)
bot.run(TOKEN)
希望您知道如何让它发挥作用.感谢您的帮助!
Hope you have an idea how to make it work. Thank you for your help!
推荐答案
您应该从开发者门户为您的机器人启用存在意图,如下图所示.
You should enable the presences intents for your bot from the developers portal like in the image below.
discord 开发者门户
https://i.stack.imgur.com/cAn8m.png
这篇关于Discord.py(重写)on_member_update 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord.py(重写)on_member_update 无法正常工作


基础教程推荐
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01