I want to write a program that checks all the channel names in discord and checks a list with names. If the name on the list is not in the channel list, it will create a new channel with that name, but I can’t seem to find an eazy, straight forward method to fetch channel names. My bot is only used in my server and will not expand. Therefore it is not necessary to use GuildID’s. The code that I have right now looks like this:
<code>text_channel_list = []
for server in client.guilds:
for channel in server.channels:
if str(channel.type) == 'text':
text_channel_list.append(channel)
<code>text_channel_list = []
for server in client.guilds:
for channel in server.channels:
if str(channel.type) == 'text':
text_channel_list.append(channel)
print(text_channel_list)
</code>
text_channel_list = []
for server in client.guilds:
for channel in server.channels:
if str(channel.type) == 'text':
text_channel_list.append(channel)
print(text_channel_list)
OUTPUT
<code>[<TextChannel id=1258428043005792400 name='????general' position=0 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258429464413474879 name='????rules' position=1 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258432560560869427 name='????ho
w-it-works' position=2 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258460564682833960 name='????all-command' position=4 nsfw=False news=False category_id=1258856562156507238>, <TextChannel id=1258804587800825946 name='????download' position=3 nsfw=False news=False category_id=1258428043005792398>]
<code>[<TextChannel id=1258428043005792400 name='????general' position=0 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258429464413474879 name='????rules' position=1 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258432560560869427 name='????ho
w-it-works' position=2 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258460564682833960 name='????all-command' position=4 nsfw=False news=False category_id=1258856562156507238>, <TextChannel id=1258804587800825946 name='????download' position=3 nsfw=False news=False category_id=1258428043005792398>]
</code>
[<TextChannel id=1258428043005792400 name='????general' position=0 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258429464413474879 name='????rules' position=1 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258432560560869427 name='????ho
w-it-works' position=2 nsfw=False news=False category_id=1258428043005792398>, <TextChannel id=1258460564682833960 name='????all-command' position=4 nsfw=False news=False category_id=1258856562156507238>, <TextChannel id=1258804587800825946 name='????download' position=3 nsfw=False news=False category_id=1258428043005792398>]
This is not what I want though. I only need the name=” part, but I don’t want to work with split-commands, as those are the bane of my existance.
I tried the “get_all_channels” command, but it returns:
<code><generator object Client.get_all_channels at 0x000001CE81171460>
<code><generator object Client.get_all_channels at 0x000001CE81171460>
</code>
<generator object Client.get_all_channels at 0x000001CE81171460>
which isn’t really useful.