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.
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.
Comments