简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM