pythondiscord.pydisnake

How do I get the server name from the prompt string? discord.py


There was a need to get the name of the server from the line with the invitation link, where this invitation actually leads. I get this line from the form. I use the disnake library (fork discord.py , therefore, I indicated it, because there are probably no differences in this regard). How can I actually do this and can I do it at all?


Solution

  • You can just use the guild property of an Invite to access the Guild and then get the Name from there.

    Example:

    invite = await bot.fetch_invite("discord.gg/example_invite")
    print(invite.guild.name)
    

    This was tested in discord.py but it should be the same in disnake.

    Documentation: https://docs.disnake.dev/en/stable/api.html?highlight=invite#disnake.Invite