【问题标题】:Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id' for discord bot命令引发异常:AttributeError:“NoneType”对象没有不和谐机器人的属性“id”
【发布时间】:2021-10-18 13:04:43
【问题描述】:
@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”。

【问题讨论】:

  • 为什么selfbot.wait_for()中有参数?

标签: python discord.py


【解决方案1】:

我很确定是ctx.guild.owner.id,在这种情况下不是找回公会所有者的正确方法

如果你想找到公会的所有者 ID,你应该启用意图并使用来自 herectx.guild.owner_id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2021-02-05
    • 2020-12-20
    • 2021-01-30
    • 2021-12-07
    • 1970-01-01
    相关资源
    最近更新 更多