我想要一个输出,它将输出机器人所在服务器内的所有(类别名称和ID+频道名称和ID(。
代码可能看起来像这样:
# catetories
@client.command()
async def list_catetories(ctx):
for category in discord.categories:
print('id: ' + category.id + ', name: ' + category.name)
# channels
@client.command()
async def channels(ctx):
for channel in discord.channels:
print('id: ' + channel.id + ', name: ' + channel.name)
解决方案
# categories
@client.command()
async def cat(ctx):
for category in ctx.message.guild.categories:
print(category.name)
# text channels
@client.command()
async def txtChannel(ctx):
for text_channel in ctx.message.guild.text_channels:
print(text_channel.name)
#voice channels
@client.command()
async def vc(ctx):
for voice_channel in ctx.message.guild.voice_channels:
print(voice_channel.name)
#all channels + categories
@client.command()
async def channels(ctx):
for channel in ctx.message.guild.channels:
print(channel.name)
有多种通道类型,因此以下代码将显示all
通道。如果你想按类型过滤,你应该检查它的类型
@client.command()
async def channels(ctx):
for channel in ctx.guild.channels:
print(f"Name: {channel.id} Id: {channel.id}")