Discord.py rewrite get_member() function returning None for all users except bot(Discord.py 重写 get_member() 函数,为除 bot 之外的所有用户返回 None)
问题描述
几个月前我做了一个愚蠢的不和谐机器人来每分钟更改我朋友的名字,但我今天更新了它,现在 get_member 函数没有返回.
I made a stupid discord bot a few months ago to change my friends name every minute, but I updated it today and now the get_member function is returning none.
@client.event
async def on_ready():
print('bot is ready!')
status = discord.Activity(name="Sam be a loser", type=discord.ActivityType.watching)
await client.change_presence(activity=status)
name_change.start()
@tasks.loop(minutes=1)
async def name_change():
server = client.get_guild(id=584112137132048387)
user = server.get_member(376388277302984714)
global english_words
global wordNumber
wordNumber = wordNumber + 1
#changes nickname to current word
await user.edit(nick=f"{english_words[wordNumber]} lookin' ass")
print(f'Word number {wordNumber}: {english_words[wordNumber]}')
#updates number in file
file = open("currentWord.txt", "w")
file.write(str(wordNumber))
file.close
我对服务器中的每个用户都尝试了相同的功能,但它没有返回所有用户,除非我将机器人的 id 放入其中.我不知道为什么会发生这种情况,因为我什至没有编辑这部分代码.
I tried the same function with every user in the server, but it returned none for all of them except when I put the bot's id in. I have no clue why this is happening since I didn't even edit this part of the code.
推荐答案
这很可能是由于最近的 discord.py 1.5 更新.声明 Bot 时需要配置 Intent.
This is most likely due to the recent discord.py 1.5 update. You are required to configure your intents when you're declaring your Bot.
什么是意图?1.5 版引入了意图.这是机器人编写方式的根本变化.意图基本上允许机器人订阅特定的事件桶.与每个意图相对应的事件记录在意图文档的单个属性中.这是一个例子:
What are intents? Version 1.5 comes with the introduction of intents. This is a radical change in how bots are written. An intent basically allows a bot to subscribe into specific buckets of events. The events that correspond to each intent is documented in the individual attribute of the Intents documentation. Here's an example:
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True # Subscribe to the privileged members intent.
bot = commands.Bot(command_prefix='!', intents=intents)
您还必须为公会相关事件启用特权意图:这里
You will also have to enable privileged intents for guild related events: Here
您可以阅读有关意图的更多信息:此处
You can read more about intents: Here
这篇关于Discord.py 重写 get_member() 函数,为除 bot 之外的所有用户返回 None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Discord.py 重写 get_member() 函数,为除 bot 之外的所有用户返回 None
基础教程推荐
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01