問題描述
我對 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 無法正常工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!