Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py-尝试获取频道数、文本频道数&;语音频道_Python_Python 3.x_Discord.py Rewrite - Fatal编程技术网

Python Discord.py-尝试获取频道数、文本频道数&;语音频道

Python Discord.py-尝试获取频道数、文本频道数&;语音频道,python,python-3.x,discord.py-rewrite,Python,Python 3.x,Discord.py Rewrite,我正在尝试获取服务器信息命令的频道数、文本频道数和语音频道数,我已经浏览了互联网,但没有找到任何内容 我不打算完整地显示服务器信息命令,而只是尝试获取频道、文本频道和语音频道的数量: @client.command() 异步def sinfo(ctx): guild=ctx.message.guild 嵌入=discord.embed(color=discord.color.orange()) embed.add_字段(name=“Server Channels:”,value=guild.Ch

我正在尝试获取服务器信息命令的频道数、文本频道数和语音频道数,我已经浏览了互联网,但没有找到任何内容

我不打算完整地显示服务器信息命令,而只是尝试获取频道、文本频道和语音频道的数量:

@client.command()
异步def sinfo(ctx):
guild=ctx.message.guild
嵌入=discord.embed(color=discord.color.orange())
embed.add_字段(name=“Server Channels:”,value=guild.Channels,inline=False)
embed.add_字段(name=“Server Text Channels:”,value=guild.Text_Channels,inline=False)
embed.add_字段(name=“Server Voice Channels:”,value=guild.Voice_Channels,inline=False)
等待ctx.send(嵌入=嵌入)

当我说“频道”时,我指的是文本频道和语音频道一起

所有这三个频道都返回一个列表,因此您只需对它们使用
len
即可获得号码

请注意,
guild.channels
将返回文本和语音频道,包括类别

因此,您的解决方案如下所示

total_text_channels = len(guild.text_channels)
total_voice_channels = len(guild.voice_channels)
total_channels = total_text_channels  + total_voice_channels 
embed.add_field(name="Server Channels: ", value=total_channels )
embed.add_field(name="Server Text Channels: ", value=total_text_channels )
embed.add_field(name="Server Voice Channels: ", value=total_voice_channels )
添加
inline=False
,如果您希望我将其删除以使其更短


下一次也可以通过Internet查看以节省您的时间。

当您在这里时,您能告诉我如何获取机器人连接到的所有公会的成员数量吗?我想把它放在它的播放状态&当它开始播放时,无需担心,它会告诉我一切