当前位置: 首页 > 知识库问答 >
问题:

Discord.py属性错误:用户对象没有属性公会

艾善
2023-03-14

我正在开发一个定制的discord机器人,主要是为了好玩。我从另一台名为Kurisu的服务器上发现了另一个discord bot,它是完全定制和开源的。这里是github:https://github.com/nh-server/Kurisu.在国防部。派克(https://github.com/nh-server/Kurisu/blob/port/cogs/mod.py),在第432行,有一个函数基本上为用户提供了无帮助角色(在服务器中,这限制了对特定通道的访问)。我正在尝试做一些类似的事情,没有声音的角色会限制你访问语音频道。我正在使用它们的一些代码,即在函数的参数中。我正在做async def takevoice(ctx,member:FetchMember):作为函数。完整功能如下:

@bot.command(name="takevoice", pass_context=True, description="Removes access to voice channels. Admin only.")
@commands.has_role("Admin") # This must be exactly the name of the appropriate role
async def takevoice(ctx, member: FetchMember):
   role = get(member.guild.roles, name="No-Voice")
   await member.add_roles(role)

我的程序中的其他函数工作得很好,但每当我尝试以另一个用户为目标运行此函数时,它都不工作,并给我一个回溯错误。它的结尾是:AttributeError:“用户”对象没有属性“公会”。我到处寻找答案,但找不到。任何帮助都将不胜感激。

谢谢

我的机器人的完整代码在这里:(我正在使用其他几个文件,所有这些文件都可以在Kurisu github的utils文件夹中找到。/>,manager.py,utils.py.我也在使用一个名为keep_alive.py的文件,因为我正在repl.it.)

import asyncio
import aiohttp
import json
import keep_alive
from discord import Game
from discord.ext.commands import Bot
import datetime
import re
import time
from subprocess import call
import discord
from discord.ext import commands
from checks import is_staff, check_staff_id, check_bot_or_staff
from database import DatabaseCog
from converters import SafeMember, FetchMember
import utils
from discord.ext import commands
from discord.utils import get
TOKEN = ""  # Get at discordapp.com/developers/applications/me
bot=commands.Bot(command_prefix=".")
client=discord.Client()

@bot.command(name="hi")
async def hi(ctx):
    await ctx.channel.send("hello")

@bot.command (name="elsewhere", description="Gives acess to the #elsewhere channel")
async def elsewhere(ctx):
    role = discord.utils.get(ctx.guild.roles, name="Elsewhere")
    user = ctx.message.author
    if role in user.roles:
        await user.remove_roles(role)
    if role not in user.roles:
        await user.add_roles(role)

共有2个答案

钱远
2023-03-14

member:FetchMember更改为member:discord。成员解决了它。这个成员需要资本化。

方通
2023-03-14

这是因为用户对象不能有一个特定的公会——用户意味着不再在公会中的人。更改async def takevoice(ctx,成员:获取成员):async def takevoice(ctx,成员:不和谐成员):和问题将被修复。这样,您将获得一个成员而不是用户对象,并且会有一个特定的公会。但是(我不知道这是否重要)你不能再对不在公会的人执行这个动作了。

 类似资料:
  • 当我执行代码时,我得到一个错误, 属性错误:“WebDriver”对象没有属性“find_element_by_xpath”

  • 问题内容: 我正在尝试读取文件,并用逗号在每行中拆分一个单元格,然后仅显示包含有关纬度和经度信息的第一和第二个单元格。这是文件: 时间, 纬度,经度 ,类型2015-03-20T10:20:35.890Z, 38.8221664,-122.7649994 ,地震 2015-03-20T10 :18:13.070Z, 33.2073333,-116.6891667 ,地震 2015-03-20T10

  • 我试图分裂链接的图像是什么错在我的代码

  • 我在Jupyter Notebook中运行Keras神经网络模型(Python 3.6) 我得到以下错误 属性错误:列表对象没有属性ndim 从K调用. fi()方法后eras.model 我检查了Keras的requirements.txt文件(在Anaconda3中),Numpy、smpy和六个模块版本都是最新的。 什么可以解释这个属性错误? 完整的错误消息如下(似乎与Numpy有些关联):

  • 我使用要连接到mysql,下面是我的Python语句: 但是有一个错误,这里是日志: 这是我的代码: 我已经创建数据库在谢谢

  • 我的代码: 我的错误: 回溯(最近一次调用last):文件“C:\Users\weqwwg\Desktop\python\Game.py”,第77行,在driver.manage().timeouts()中。隐式等待(10,时间单位:秒);AttributeError:“WebDriver”对象没有属性“manage” 我正在尝试向youtube上的评论框发送密钥。我删除了一些代码,我目前正在运行