-1

So, I wrote some code, that sends a message to each channel in a server;

server_id = 974656708672925260
            message = "test"
            thread = 20
            channels = client.get_guild(server_id).text_channels
            channel_count = len(channels)
            for i in range(thread):
                for i in range(channel_count):
                    channel = client.get_channel(channels[i].id)
                    await channel.send(message)

And when the bot does not have permission to send messages in the server, i get en error. Is it possible to just ignore that channel, and jump to the next one?

  • Please note that, although unrelated to the question, it is not good practice to use the same variable name for the inner and outer loop. – TheFungusAmongUs May 13 '22 at 13:10
  • 1
    Does this answer your question? [How to properly ignore exceptions](https://stackoverflow.com/questions/730764/how-to-properly-ignore-exceptions) – TheFungusAmongUs May 13 '22 at 13:14
  • 1
    See the above. But don't catch everything, only `discord.errors.Forbidden`, otherwise other unrelated errors will be ignored. – Eric Jin May 13 '22 at 21:02

0 Answers0