Discord.py获取公会(python)成员的所有名称和描述


import discord
class Bot(discord.Client):
def __init__(ctx, **kwargs):
super().__init__(**kwargs)
ctx.loop.create_task(ctx.get_all_members())
async def get_all_members(ctx):
for member in ctx.guild.members:
print(member)
bot = Bot()
bot.run("My Token Here", bot=False)

**错误

第10行,在get_all_members中对于ctx.guild.members中的成员:AttributeError:"Bot"对象没有属性"guild">

您应该不协调地使用以下命令来运行它$get_names

请记住,如果你在公会中有很多成员,它会出错,因为它不能发送大消息。但您可以将其保存为txt或仅printit


import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="$")

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

@bot.command()
async def get_names(ctx):
names = list()
for user in ctx.guild.members:
names.append(user.name)

await ctx.channel.send('n'.join(names))
bot.run(TOKEN_HERE)

最新更新