如何检查我的Discord僵尸程序已加入/位于哪些服务器?不和谐

时间:2018-09-08 13:56:53

标签: python bots discord discord.py discord.py-rewrite

我想检查一下我的discord机器人所在的服务器,请注意,我不知道如何使用discord.client(该机器人是用discord.py编写的)

到目前为止我尝试过的代码是:

@bot.command(pass_context=True)
async def servers(ctx):
client = discord.Client()
servers = list(client.servers)
await bot.say("Connected on " + str(len(client.servers)) + " servers:")
for x in range(len(servers)):
    await bot.say(" "+servers[x-1].name)

(请注意,缩进正确,但是堆栈溢出未正确显示)

2 个答案:

答案 0 :(得分:0)

您可以这样做

@bot.command()
async def servers():
  servers = list(bot.servers)
  await bot.say(f"Connected on {str(len(servers))} servers:")
  await bot.say('\n'.join(server.name for server in servers))

答案 1 :(得分:-1)

这对我有用,来自https://www.devdungeon.com/content/make-discord-bot-python-part-2

  async def list_servers():
  await client.wait_until_ready()
  while not client.is_closed:
     print("Current servers:")
     for server in client.servers:
        print(server.name)
     await asyncio.sleep(600)

client.loop.create_task(list_servers())