【发布时间】:2021-06-06 22:34:00
【问题描述】:
我正在创建一个不和谐机器人,我想创建一个 serverinfo 命令,并且我希望其中一个文本显示服务器中的频道数量。
我遇到的问题是我希望公告通道也被考虑在内,但公告通道是文本通道,所以这意味着它们被添加到文本通道的总数中。我也不知道公告频道的代码是什么,我翻遍了discord.py文档
我正在使用 Python 3.9.5,并且我相信我正在使用最新版本的 discord 模块,因为当我从命令提示符处再次安装它时,它说“要求已经满足:c 中的 discord.py: \users\plant\appdata\local\programs\python\python39\lib\site-packages (1.7.2)"
我想要来自 tatsu bot 的类似的东西
我的频道代码
categories = ctx.guild.categories
text_channels = ctx.guild.text_channels
#announcements_channels = ctx.guild.announcements_channels
embed.add_field(name = f"Channels[{len(categories)+len(text_channels)}]",
value = f"Category: {len(categories)}\nText: {len(text_channels)}\nNews: ",
inline = False)
我的 serverinfo 命令代码
@client.command(name = "serverinfo", description = "Shows info about the current server.", aliases=["server"])
async def serverinfo(ctx):
embed = discord.Embed(title = f"{ctx.guild.name}", description = ".", colour = white)
roleCount = len(ctx.guild.roles)
bots = [bot.mention for bot in ctx.guild.members if bot.bot]
embed.set_thumbnail(url = str(ctx.guild.icon_url))
embed.add_field(name = f"ID: **{ctx.guild.id}**", value = "⠀", inline = False)
embed.add_field(name = "Verification Level", value = str(ctx.guild.verification_level).capitalize(), inline = False)
embed.add_field(name = "Region", value = str(ctx.guild.region).capitalize(), inline = False)
categories = ctx.guild.categories
text_channels = ctx.guild.text_channels
#announcements_channels = ctx.guild.announcements_channels
embed.add_field(name = f"Channels[{len(categories)+len(text_channels)}]",
value = f"Category: {len(categories)}\nText: {len(text_channels)}\nNews: ",
inline = False)
embed.add_field(name = "Server Owner", value = str(ctx.guild.owner.mention), inline = False)
embed.add_field(name = "Created On", value = ctx.guild.created_at.strftime("%a, %#d %B %Y, %I:%M %p UTC"), inline = False)
embed.add_field(name = f"Roles[{len(ctx.guild.roles)}]", value = "⠀", inline = False)
embed.set_footer(icon_url = str(ctx.author.avatar_url), text = f"Requested by {ctx.author.name}")
await ctx.send(embed = embed)
【问题讨论】:
标签: python discord discord.py