Home>
I'm developing a bot with Discord.py. I want to understand how to write a function that will itself determine the name of the server on which the bot is located.
-
Answer # 1
-
Answer # 2
In class Guild, there is an attribute that returns the name of the server.
Example1:
from discord.ext import commands bot= commands.Bot() # Suppose we have a command *name* @bot.command() async def name(ctx: commands.Context): # Get the name of the server guild_name= ctx.guild.name # Do something next ...
Example2:
from discord import Guild from discord.ext import commands bot= commands.Bot() def get_guild_name(guild_id: int): # "Getting" the server guild: Guild= bot.get_guild(guild_id) # Server name guild_name= guild.name return guild_name
Related questions
- python : How to make a discord message orange?
- python : Yo. In general, I decided to learn how to create bots for discord, but there was one tiny problem, I can’t install
- python : Instead of one line, everything is deleted!
- python : The bot does not find the command
- python : how to make it so that if the author's messages are above the bot role, then return?
- python : How to implement the mute discord.py command?
- python : How to make a discord bot send a message to the chat every 10 seconds?
- Can't start python discord bot
- python : Discord bot won't start
In class Guild, there is an attribute that returns the name of the server.
Example1:
Example2: