Команда вызвала исключение: ошибка атрибута: объект ‘NoneType’ не имеет атрибута ‘id’ для discord bot

python #discord.py

#python #discord.py

Вопрос:

 @voice.command()
@commands.has_permissions(administrator=True)
async def setup(self, ctx, member: discord.Member = None ):
    conn = sqlite3.connect('voice.db')
    c = conn.cursor()
    guildID = ctx.guild.id
    id = ctx.author.id
    if ctx.author.id == ctx.guild.owner.id or ctx.author.id == 189887758192476162:
        def check(m):
            return m.author.id == ctx.author.id
        await ctx.channel.send("**You have 60 seconds to answer each question!**")
        await ctx.channel.send(f"**Enter the name of the category you wish to create the channels in:(e.g Voice Channels)**")
        try:
            category = await self.bot.wait_for('message', check=check, timeout = 60.0)
        except asyncio.TimeoutError:
            await ctx.channel.send('Took too long to answer!')
        else:
            new_cat = await ctx.guild.create_category_channel(category.content)
            await ctx.channel.send('**Enter the name of the voice channel: (e.g Join To Create)**')
            try:
                channel = await self.bot.wait_for('message', check=check, timeout = 60.0)
            except asyncio.TimeoutError:
                await ctx.channel.send('Took too long to answer!')
            else:
                try:
                    channel = await ctx.guild.create_voice_channel(channel.content, category=new_cat)
                    c.execute("SELECT * FROM guild WHERE guildID = ? AND ownerID=?", (guildID, id))
                    voice=c.fetchone()
                    if voice is None:
                        c.execute ("INSERT INTO guild VALUES (?, ?, ?, ?)",(guildID,id,channel.id,new_cat.id))
                    else:
                        c.execute ("UPDATE guild SET guildID = ?, ownerID = ?, voiceChannelID = ?, voiceCategoryID = ? WHERE guildID = ?",(guildID,id,channel.id,new_cat.id, guildID))
                    await ctx.channel.send("**You are all setup and ready to go!**")
                except:
                    await ctx.channel.send("You didn't enter the names properly.nUse `.voice setup` again!")
    else:
        await ctx.channel.send(f"{ctx.author.mention} only the owner of the server can setup the bot!")
    conn.commit()
    conn.close()
 

Все интервалы указаны правильно. Он выдает ошибку, указанную в заголовке, и не сообщает, в какой строке находится ошибка. Если бы кто-нибудь мог предложить какую-то обратную связь, это было бы потрясающе. Я просто не знаю, о каком «id» может идти речь.

Комментарии:

1. Почему у вас есть self в качестве параметра в bot.wait_for() ?

Ответ №1:

Я почти уверен, что это ctx.guild.owner.id , и в этом случае это неправильный способ получить владельца гильдии

Если вы хотите найти идентификатор владельца гильдии, вы должны включить intents и использовать ctx.guild.owner_id отсюда