-
Im trying to make a registery bot, for usage firstly bot have to check is there already have registery channel in discord server.
Then i tried to get 'registery' channel with discord.Utils.get command but seems like it wasnt work like the other command.
In documentation it says if bot cant able to find/get channel return output is None, but i always get False return from this code whenever i run it, so probably it returns None everytime. Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
However you're comparing it to a string which will always be def checkforchannel(channelname_to_check):
channel = discord.utils.get(client.get_all_channels(), name=channelname_to_check)
return channel is not None Note however as I hinted on above that def check_for_channel(channel_name):
# Replace with your guild's guild ID
guild = client.get_guild(81384788765712384)
if guild is None:
# This can happen if the lookup failed
return False
channel = discord.utils.get(guild.channels, name=channel_name)
return channel is not None You can further restrict this by using |
Beta Was this translation helpful? Give feedback.
-
I did not know it! Thanks for sharing @Rapptz |
Beta Was this translation helpful? Give feedback.
discord.utils.get
gets the object orNone
if it's not found. Sochannel
is either adiscord.abc.GuildChannel
(which can either bediscord.TextChannel
,discord.CategoryChannel
,discord.StoreChannel
, ordiscord.VoiceChannel
) orNone
.However you're comparing it to a string which will always be
False
. To fix your code do the following:Note however as I hinted on above that
get_all_channels
goes through all channels in every guild your bot is on. It's probably a good idea to restrict the search to something that either belongs to a sp…