Discord.py获取社区服务器规则与版主更新频道方法咨询
获取Discord社区服务器的规则频道与版主更新频道(discord.py)
- 规则频道:使用
Guild.rules_channel属性,返回对应规则频道的TextChannel实例,服务器未配置时返回None。 - 版主更新频道:使用
Guild.moderation_log_channel属性,返回对应版主日志(更新)频道的TextChannel实例,未配置时返回None。
代码示例
# 示例:通过命令获取当前服务器的目标频道 @bot.command() async def fetch_community_channels(ctx): rules_channel = ctx.guild.rules_channel mod_updates_channel = ctx.guild.moderation_log_channel msg_parts = [] if rules_channel: msg_parts.append(f"规则频道:{rules_channel.name}(ID: {rules_channel.id})") else: msg_parts.append("该服务器未设置规则频道") if mod_updates_channel: msg_parts.append(f"版主更新频道:{mod_updates_channel.name}(ID: {mod_updates_channel.id})") else: msg_parts.append("该服务器未设置版主更新频道") await ctx.send("\n".join(msg_parts))
内容的提问来源于stack exchange,提问作者Master Oogway
相关产品推荐
相关产品推荐

