Получить полный список серверов - PullRequest
0 голосов
/ 31 мая 2018

Итак, как получить список всех серверов, которые мой бот подключил или установил.Я использовал приведенный ниже код, но теперь он работает, не зная почему.

servers = list(bot.servers)
print("Connected on " + str(len(bot.servers)) + "servers:")
for x in range(len(servers)):
    print('  ' + servers[x-1].name)

Мой полный код bot.py

token = "This is my Token" # This is what the bot uses to log into Discord.
prefix = "?" # This will be used at the start of commands.

import discord
from discord.ext import commands
from discord.ext.commands import Bot

bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print(discord.__version__)
    print('------')

@bot.command(pass_context=True)
async def ping(ctx):
    msg = 'Pong {0.author.mention}'.format(ctx.message)
    await bot.say(msg)

@bot.command(pass_context=True)
async def hello(ctx):
    msg = 'hello... {0.author.mention}'.format(ctx.message)
    await bot.say(msg)

bot.run(token)

1 Ответ

0 голосов
/ 31 мая 2018

Не уверен, где вы используете код для поиска серверов, но в вашем случае использование bot.servers возвращает итерацию всех серверов, которые бот может видеть.

Выможете изменить ваше on_ready событие, чтобы распечатать все имена серверов.

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print(discord.__version__)
    print('------')

    print('Servers connected to:')
    for server in bot.servers:
        print(server.name)
...