Python 如何获取我的bot处于discord.py中的服务器列表
我想使用一个命令打印我的机器人所在的服务器列表。这就是我所拥有的。当我使用命令时,它发送“property object at 0x000001988E164270”,而不是服务器名称列表Python 如何获取我的bot处于discord.py中的服务器列表,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我想使用一个命令打印我的机器人所在的服务器列表。这就是我所拥有的。当我使用命令时,它发送“property object at 0x000001988E164270”,而不是服务器名称列表 import discord from discord.ext import commands client = discord.Client activeservers = client.guilds class OwnerCommands(commands.Cog): def __init_
import discord
from discord.ext import commands
client = discord.Client
activeservers = client.guilds
class OwnerCommands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("OwnerCommands Is Ready")
@commands.command()
async def servers(self, ctx):
await ctx.send(activeservers)
print(activeservers)
def setup(client):
client.add_cog(OwnerCommands(client))
是机器人程序连接到的所有公会的列表。您需要对其进行迭代
此外,activeservers=client.guilds
在bot连接之前被调用,这意味着列表将为空。将其移动到命令内部,以在调用命令时获得最新列表
import discord
from discord.ext import commands
client = discord.Client
class OwnerCommands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("OwnerCommands Is Ready")
@commands.command()
async def servers(self, ctx):
activeservers = client.guilds
for guild in activeservers:
await ctx.send(guild.name)
print(guild.name)
def setup(client):
client.add_cog(OwnerCommands(client))
是机器人程序连接到的所有公会的列表。您需要对其进行迭代
此外,activeservers=client.guilds
在bot连接之前被调用,这意味着列表将为空。将其移动到命令内部,以在调用命令时获得最新列表
import discord
from discord.ext import commands
client = discord.Client
class OwnerCommands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("OwnerCommands Is Ready")
@commands.command()
async def servers(self, ctx):
activeservers = client.guilds
for guild in activeservers:
await ctx.send(guild.name)
print(guild.name)
def setup(client):
client.add_cog(OwnerCommands(client))