How to get rid of Text Channels from channel list in Discord.py

Kewbin

Here I have some examle code:

for server in client.servers:
        for channel in server.channels:
            print(channel)

And the output is for example:

Text Channels
general
commands
Text Channels
main-channel
admin-channel
Text Channels
first-channel

I'd like to make command !br that will send message to the 1st channel in each server. But I can't because the Text Channels line counts as channel as well

Here's little image what I mean by Text Channels

And I always get an error like this:

Cannot send messages in a non-text channel

So I'd like to skip these channels when they appear or delete them completely from the channel list.

Here is the full code of the command:

elif message.content.startswith('!br'):
    for server in client.servers:
        for channel in server.channels:
            if channel.permissions_for(server.me).send_messages:
                await client.send_message(channel, str(message.content[4:] )
                break

Thank you for your answers.

toheedNiaz

If you want to check that the channel is a text channel, you would use channel.type. Documentation here. You just need to check that channel should be of type text.

elif message.content.startswith('!br'):
    for server in client.servers:
        for channel in server.channels:
            if (channel.permissions_for(server.me).send_messages) and (channel.type == "text"):
                await client.send_message(channel, str(message.content[4:] )
                break

channel.type == discord.ChannelType.text will check if the channel is a text channel so that you can send a message.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I get a list of all the messages in a channel and then pick a random message from that list to send as a message?

From Java

message.channel.id Discord PY

From Java

How to get Member object from user id discord.py

From Dev

How to get a list of available channels from Pusher?

From Dev

How to get rid from spam MySQL insert?

From Dev

How to get rid of the dots on the side of list items?

From Dev

How to get rid of toolbar text?

From Dev

How to create a category and a channel using python discord.py

From Dev

How to make a bot join voice channels discord.py

From Dev

Get last message from text channel with discord.js

From Dev

Sending a message to all channels — Discord.py

From Dev

Discord py how can I join a voice channel

From Dev

Get the channel deletor discord py

From Dev

How to check if a channel has any messages? Discord.py

From Dev

How to get rid of toolbar text?

From Dev

How to get a list of available channels from Pusher?

From Dev

How to get rid of curly braces from expanded list

From Dev

How to get newly inserted @rid from OrientDb?

From Dev

how to get rid of that "end of text"

From Dev

How do I get rid of "K" from a list of string which I want to be integer

From Dev

How to get rid of \N from pig result

From Dev

discord.py How to get logs from a DM channel

From Dev

Iterating through a list containing text to get rid of certain values

From Dev

Discord.js - How to spam messages in a text channel?

From Dev

Bing channel does not appear in channels list for botframework

From Dev

how to get rid of Js Undefined from here?

From Dev

How do I move a user to a specific channel on discord using the discord.py API

From Dev

discord.py | how to get list user banned name and id

From Dev

How to get list of Channel administrators from the Telegram API?

Related Related

  1. 1

    How can I get a list of all the messages in a channel and then pick a random message from that list to send as a message?

  2. 2

    message.channel.id Discord PY

  3. 3

    How to get Member object from user id discord.py

  4. 4

    How to get a list of available channels from Pusher?

  5. 5

    How to get rid from spam MySQL insert?

  6. 6

    How to get rid of the dots on the side of list items?

  7. 7

    How to get rid of toolbar text?

  8. 8

    How to create a category and a channel using python discord.py

  9. 9

    How to make a bot join voice channels discord.py

  10. 10

    Get last message from text channel with discord.js

  11. 11

    Sending a message to all channels — Discord.py

  12. 12

    Discord py how can I join a voice channel

  13. 13

    Get the channel deletor discord py

  14. 14

    How to check if a channel has any messages? Discord.py

  15. 15

    How to get rid of toolbar text?

  16. 16

    How to get a list of available channels from Pusher?

  17. 17

    How to get rid of curly braces from expanded list

  18. 18

    How to get newly inserted @rid from OrientDb?

  19. 19

    how to get rid of that "end of text"

  20. 20

    How do I get rid of "K" from a list of string which I want to be integer

  21. 21

    How to get rid of \N from pig result

  22. 22

    discord.py How to get logs from a DM channel

  23. 23

    Iterating through a list containing text to get rid of certain values

  24. 24

    Discord.js - How to spam messages in a text channel?

  25. 25

    Bing channel does not appear in channels list for botframework

  26. 26

    how to get rid of Js Undefined from here?

  27. 27

    How do I move a user to a specific channel on discord using the discord.py API

  28. 28

    discord.py | how to get list user banned name and id

  29. 29

    How to get list of Channel administrators from the Telegram API?

HotTag

Archive