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

Question:

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?

Asked By: Kovirum

||

Answers:

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

Answered By: moinierer3000
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.