Home > Blockchain >  Getting function instead of link
Getting function instead of link

Time:10-28

So i have made a command for my friends' servers so we can have list of invites to our servers. When i run the bot and type ".servers" i'm getting <function owner.servers..serversInvite at 0x0000022903A75B40> instead of invite link.

    @commands. command()
    async def servers(self, ctx):
        async def serversInvite(guild = discord.Guild):
            for guild in self.bot.guilds:
                channel = guild.text_channels[0]
                link = await channel.create_invite(max_age=0)
                invitelink = str(link)
            if link:
                msg = '```js\n'
                for guild in self.bot.guilds:
                    msg  = f'ID: {guild.id} | Members: {guild.member_count} | Guild Name: {guild.name} | Owner: {guild.owner} | Server Invite: {serversInvite}\n'
                msg  = '```'
                await ctx.send(msg)
            else:
                msg = '```js\n'
                for guild in self.bot.guilds:
                    msg  = f'ID: int({guild.id}) | Members: {guild.member_count} | Guild Name: {guild.name} | Owner: {guild.owner} | \n'
                msg  = '```'
                await ctx.send(msg)

CodePudding user response:

Your variable invitelink defined as:

invitelink = str(link)

is not used in your code.

Didn't you mean in the following line to use the invitelink in place of the serversInvite?

Before

msg  = f'ID: {guild.id} ... | Server Invite: {serversInvite}\n'

After

msg  = f'ID: {guild.id} ... | Server Invite: {invitelink}\n'

By the way, the serversInvite function parameter guild is not used, as the guild used later in the function is an item of self.bot.guilds.

EDIT 1: what about the following changes ?

@commands. command()
async def servers(self, ctx):
    async def serversInvite(guild = discord.Guild):
        for index, guild in enumerate(self.bot.guilds):
            channel = guild.text_channels[0]
            link = await channel.create_invite(max_age=0)
            invitelink = str(link)
            if link:
                msg = '```js\n'
                msg  = f'ID: {guild.id} | Members: {guild.member_count} | Guild Name: {guild.name} | Owner: {guild.owner} | Server Invite: {invitelink}\n'
                msg  = '```'
                await ctx.send(msg)
            else:
                msg = '```js\n'
                msg  = f'ID: int({guild.id}) | Members: {guild.member_count} | Guild Name: {guild.name} | Owner: {guild.owner} | \n'
                msg  = '```'
                await ctx.send(msg)
  • Related