Discord.py List all server names where the bot is in

Question:

I made a bot but I want the bot to make list all the server names where it is when you type a command.
Can any one help me, please?

Asked By: User456

||

Answers:


await ctx.send('n'.join(guild.name for guild in bot.guilds))

Just remember to pass an intent with guilds enabled in your bot’s constructor

Answered By: ChrisDewa
@commands.command()
async def servers(self, ctx):
    activeservers = client.guilds
    for guild in activeservers:
        await ctx.send(guild.name)
        print(guild.name)

This code should work

Answered By: DevJelle
@client.command()
async def server(ctx):
  servers = list(client.guilds)
  for server in servers:
    await ctx.send(server.name)

it works for me…

Answered By: Aditya Bhoyar
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.