discorddiscord.pyvanity-url

Python detects Vanity URL discord.py


I am making a Serverinfo command on my bot. So i want add the server info command show the guild's vanity too! But I read the whole discord documentation but can't find how can i make the bot detect the vanity url and sends it. Then I tried to test by making that command as a single command. Here is my code:

@bot.command()
async def vanity(ctx):
  vanity = str(ctx.guild.vanity_url)
  await ctx.send(vanity)

The bot doesn't response with the code. A help will be appreciated. Thanks in advance.


Solution

  • Try this to get the vanity url:

    vanity = (await ctx.guild.vanity_invite()).url
    

    Documentation reference: https://discordpy.readthedocs.io/en/stable/api.html#discord.Guild.vanity_invite