Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python不协调:get_member()不返回成员对象_Python_Discord_Attributeerror - Fatal编程技术网

python不协调:get_member()不返回成员对象

python不协调:get_member()不返回成员对象,python,discord,attributeerror,Python,Discord,Attributeerror,我有一个discord机器人,它运行得很好,不知怎么的,我遇到了一个问题,我想在我的discord服务器中获取成员的名称。它只是说没有一个函数没有属性名,这让我想到函数可能无法正常工作。。。我只是展示了我得到的错误: import discord TOKEN = "" class DiscordClass(discord.Client): async def on_message(self, message): user_id = message

我有一个discord机器人,它运行得很好,不知怎么的,我遇到了一个问题,我想在我的discord服务器中获取成员的名称。它只是说没有一个函数没有属性名,这让我想到函数可能无法正常工作。。。我只是展示了我得到的错误:

import discord

TOKEN = ""

class DiscordClass(discord.Client):

    async def on_message(self, message):
        user_id = message.author.id
        member = message.guild.get_member(user_id)
        print(member.name)

client = DiscordClass()
client.run(TOKEN)
OUT:AttributeError:“非类型”对象没有属性“名称”

附言:我对Stackoverflow是新手,如果我做错了什么,我很抱歉

编辑: 真的,我真的不知道我在这里做了什么,文档没有什么帮助(至少对我来说,我一直在用它们做所有其他的事情……我可能在python方面没有达到解决这个问题的水平)

出:还是一样的错误

在文件中,他们说在创业时使用chunk\u guilds\u将是另一种选择。。。这样做之后,我得到了这样一条信息:“ValueError:Intents.members必须在启动时启用区块公会。”

从中可以看到“如果fetch\u offline\u members设置为False,则用户缓存将不存在。这使得执行许多操作变得困难或不可能,例如:

  • Guild.get_member()通常不可用。“
因此,您的成员变量没有类型,因此也没有名为name的属性

可能将fetch_offline_members设置为True,然后重试

干杯,米加


编辑:正如您所说,chunk\u guilds\u at\u startup是fetch\u offline\u成员的新属性。当您将此设置为True时,您会收到另一条错误消息。因此,Intents.members必须设置为True

谢谢你迄今为止的帮助!它什么时候改变了“fetch\u all\u members”在默认情况下不再设置为True?因为它起作用了,然后就没有了。。。另外,你不必用小写字母写“Guild”…也许可以尝试将intent.members设置为True?
import discord

TOKEN = ""

class discordClass(discord.AutoShardedClient):

    def __init__(self):
        super().__init__(fetch_all_members=True)

    async def on_message(self, message):
        user_id = message.author.id
        member = message.guild.get_member(user_id)
        print(message.guild.owner)
        print(member.name)

client = discordClass()
client.run(TOKEN)