#๐Ÿ”’ TypeError: unsupported type annotation <class discord.guild.Guild >

41 messages ยท Page 1 of 1 (latest)

storm hill
#

hey, always working on my discord bot but this command (server info command) i just made gives me an error and i can't find anything on the net, please help !


    @app_commands.command(
        name = "sinfo", 
        description = description["sinfo"]
        )
    async def sinfo(self, interaction: discord.Interaction, server: discord.Guild | None):

        date_format = "โ†ณ *%a, %d %b %Y %I:%M %p*"
        creator = await self.bot.fetch_user(int(os.getenv('CREATOR_ID')))
        owner = server.owner

        if server is None:
            server = interaction.guild.id

        #page 1
        embed_page1=discord.Embed(color=0x0E2863)
        embed_page1.set_author(name=server.name, icon_url=server.icon)
        embed_page1.set_thumbnail(url=server.icon)

        embed_page1.add_field(name="ID", value=f'โ†ณ `{server.id}`', inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        invite = server.invites([0])
        embed_page1.add_field(name="Invite Link", value=f'โ†ณ {invite}', inline = True)

        embed_page1.add_field(name="Server Created", value=server.created_at.strftime(date_format), inline = False)
        embed_page1.add_field(name="Members", value=server.member_count, inline = False)

        embed_page1.add_field(name="Text channels", value=server.text_channels, inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        embed_page1.add_field(name="Voice channels", value=server.voice_channels, inline = True)

        embed_page1.set_footer(text=f'Bot by {creator.name} ๐Ÿ–ค')
        embed_page1.timestamp = datetime.datetime.now(datetime.UTC)

        #page 2
        embed_page2=discord.Embed(color=0x0E2863)
        name = owner.name if owner.global_name is None else owner.global_name
        embed_page2.set_author(name=name, icon_url=owner.avatar)
        embed_page2.set_thumbnail(url=owner.avatar)

        embed_page2.add_field(name="ID", value=f'โ†ณ `{owner.id}`', inline = True)
        embed_page2.add_field(name=f'\t', value=f'\t', inline=True)
        embed_page2.add_field(name="Nickname", value=f'โ†ณ {owner.name}', inline = True)

        embed_page2.add_field(name="Account Created", value=owner.created_at.strftime(date_format), inline = False)
        embed_page2.add_field(name="Join Date", value=owner.joined_at.strftime(date_format), inline = True)
        embed_page2.add_field(name=f'\t', value=f'\t', inline=True)
        members = sorted(server.members, key=lambda m: m.joined_at)
        embed_page2.add_field(name="Join position", value=str(members.index(owner)+1), inline = True)

        embed_page2.set_footer(text=f'Bot by {creator.name} ๐Ÿ–ค')
        embed_page2.timestamp = datetime.datetime.now(datetime.UTC)
TypeError: unsupported type annotation <class discord.guild.Guild >

i am using discord.py btw

subtle valveBOT
#

@storm hill

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cunning junco
#

maybe you can have your users type in a guild ID

storm hill
cunning junco
storm hill
#

ooooh I see

#

trying this then

cunning junco
#

you will also have to use guild = bot.get_guild(server_id) inside your command body

#

or client or whatever your instance name is

storm hill
#

it is in a cog

#

so self.bot if i am correct

#

@cunning junco I changed everything but it doesn't recognize the variables

#
@app_commands.command(
        name = "sinfo", 
        description = description["sinfo"]
        )
    async def sinfo(self, interaction: discord.Interaction, server_id: int | None):

        guild = self.bot.get_guild(server_id)
        date_format = "โ†ณ *%a, %d %b %Y %I:%M %p*"
        creator = await self.bot.fetch_user(int(os.getenv('CREATOR_ID')))
        owner = guild.owner

        if server_id is None:
            server_id = interaction.guild.id

        #page 1
        embed_page1=discord.Embed(color=0x0E2863)
        embed_page1.set_author(name=guild.name, icon_url=guild.icon)
        embed_page1.set_thumbnail(url=guild.icon)

        embed_page1.add_field(name="ID", value=f'โ†ณ `{guild.id}`', inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        invite = guild.invites([0])
        embed_page1.add_field(name="Invite Link", value=f'โ†ณ {invite}', inline = True)

        embed_page1.add_field(name="Server Created", value=guild.created_at.strftime(date_format), inline = False)
        embed_page1.add_field(name="Members", value=guild.member_count, inline = False)

        embed_page1.add_field(name="Text channels", value=guild.text_channels, inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        embed_page1.add_field(name="Voice channels", value=guild.voice_channels, inline = True)

        embed_page1.set_footer(text=f'Bot by {creator.name} ๐Ÿ–ค')
        embed_page1.timestamp = datetime.datetime.now(datetime.UTC)
#

discord.app_commands.errors.CommandInvokeError: Command 'sinfo' raised an exception: AttributeError: 'NoneType' object has no attribute 'owner'

cunning junco
# storm hill

its probably too large to be a number. hm. i suppose it will have to be a string then, and you will have to convert it to an int using int()

storm hill
#

when i do /sinfo id it tells me this :
discord.app_commands.errors.CommandInvokeError: Command 'sinfo' raised an exception: TypeError: Guild.invites() takes 1 positional argument but 2 were given

#

and when i do /sinfo it tells me this :

storm hill
#

i fixed it but the invites thing is still a problem

cunning junco
#

show your new code

storm hill
#
    @app_commands.command(
        name = "sinfo", 
        description = description["sinfo"]
        )
    async def sinfo(self, interaction: discord.Interaction, server_id: str | None):

        date_format = "โ†ณ *%a, %d %b %Y %I:%M %p*"
        creator = await self.bot.fetch_user(int(os.getenv('CREATOR_ID')))

        if server_id is None:
            server_id = interaction.guild.id

        guild = self.bot.get_guild(int(server_id))
        owner = guild.owner

        #page 1
        embed_page1=discord.Embed(color=0x0E2863)
        embed_page1.set_author(name=guild.name, icon_url=guild.icon)
        embed_page1.set_thumbnail(url=guild.icon)

        embed_page1.add_field(name="ID", value=f'โ†ณ `{guild.id}`', inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        invite = guild.invites([0])
        embed_page1.add_field(name="Invite Link", value=f'โ†ณ {invite}', inline = True)

        embed_page1.add_field(name="Server Created", value=guild.created_at.strftime(date_format), inline = False)
        embed_page1.add_field(name="Members", value=guild.member_count, inline = False)

        embed_page1.add_field(name="Text channels", value=guild.text_channels, inline = True)
        embed_page1.add_field(name=f'\t', value=f'\t', inline=True)
        embed_page1.add_field(name="Voice channels", value=guild.voice_channels, inline = True)

        embed_page1.set_footer(text=f'Bot by {creator.name} ๐Ÿ–ค')
        embed_page1.timestamp = datetime.datetime.now(datetime.UTC)

        #page 2
        embed_page2=discord.Embed(color=0x0E2863)
        name = owner.name if owner.global_name is None else owner.global_name
        embed_page2.set_author(name=name, icon_url=owner.avatar)
        embed_page2.set_thumbnail(url=owner.avatar)

        embed_page2.add_field(name="ID", value=f'โ†ณ `{owner.id}`', inline = True)
        embed_page2.add_field(name=f'\t', value=f'\t', inline=True)
        embed_page2.add_field(name="Nickname", value=f'โ†ณ {owner.name}', inline = True)

        embed_page2.add_field(name="Account Created", value=owner.created_at.strftime(date_format), inline = False)
        embed_page2.add_field(name="Join Date", value=owner.joined_at.strftime(date_format), inline = True)
        embed_page2.add_field(name=f'\t', value=f'\t', inline=True)
        members = sorted(guild.members, key=lambda m: m.joined_at)
        embed_page2.add_field(name="Join position", value=str(members.index(owner)+1), inline = True)

        embed_page2.set_footer(text=f'Bot by {creator.name} ๐Ÿ–ค')
        embed_page2.timestamp = datetime.datetime.now(datetime.UTC)
#

ok so

#

i tried this

#
inv = []
        for i in guild.invites():
            inv.append(i)
        inv.reverse()
        invite = [inv[0]]
        embed_page1.add_field(name="Invite Link", value=f'โ†ณ {invite}', inline = True)
#

but it tells me guild.invites() is not iterable

#

bruh it is a coroutine

#

im dumb

cunning junco
storm hill
#

OH

#

it's working

#

it needs some tweaking but it works

cunning junco
#

๐Ÿ‘

storm hill
#

thanks again robin you are my savior

cunning junco
#

<3

storm hill
#

luv u bro

subtle valveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.