0
votes

I want my discord bot to return the channels it has access to in a certain guild, I was using:

for i in guild.categories:
      channel_list = []
      for j in i.channels:
        channel_list.append(f"- {j.name}, {j.id}")

but that returns the all channels of the guild. How can I check to see if the bot has permissions to read the channel so I can only see the channels the bot has been allowed to see?

1

1 Answers

2
votes

I think you are looking for bot.get_all_channels(), as written in the documentation: "A generator that retrieves every abc.GuildChannel the client can ‘access’.", so you will not need to verify the bot can ‘see’ the channel. Be careful as you might also retrieve Voice channels via this function

Otherwise, you can still iterate over all the channels in the category, and use channel.permissions_for(guild.me).view_channel ( https://discordpy.readthedocs.io/en/latest/api.html?highlight=me#discord.Guild.me, https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.view_channel ) that will return True if the bot can see the channel, else False

Your code will then be :

for i in guild.categories:
      channel_list = []
      for j in i.channels:
        if j.permissions_for(guild.me).view_channel:
            channel_list.append(f"- {j.name}, {j.id}")