#List all text channels in 2 lines or less
1 messages · Page 1 of 1 (latest)
list comprehension
ctx.guild.text_channels is already a list
How doI add CTX object sorry for being annoying
what do you mean?
I mean when I camm CTX I get undefined
example:
async def main(self, ctx):
await ctx.respond(ctx.guild.text_channels)
...
also may have found a solution for this:
async def test(self, ctx):
await ctx.respond([items.name for items in ctx.guild.text_channels])
Am I able to pass this to the on_message(message) function, mainly since when I try I get an error about missing 1 requires positonal argument 'message'
probably would look something like this:
async def on_message(message):
await ctx.respond([items.name for items in message.guild.text_channels])
huh I tried something like that but it keeps saying ctx is undefined
do I need to import anything else other than discord
I am pretty sure that is what is wrong
since I only have pycord imported
and asyncio and my keys file
async def on_message(message):
await message.channel.send([items.name for items in message.guilds.text_channels])
This should prob work
you would normally use ctx in a command not an event
ah ok
ah how would I go about it within a function
mainly since I need to run a function on startup for syncing channels
wdym by that
when the bot first starts up ?
so this a discord to slack bridge, the bot get's a list of channels from both services and checks them
IE if one channels does not exist on slack it is added
or visa versa
slack is like work discord
just discord but for professionals
oh
I already got most of the slack stuff worked out just the discord stuff is needed
so the way i would approach this is to create an asyncio task when the bot starts up, and within that task, constantly listen for any changes either discord's websocket gateway or slack's websocket gateway
there are many ways to do it, but this is how i would do it
what I have done is I have slack in socket mode, and pycord both in asyncio task. The biggest issue I want is while I can listen to event to sync changes in real time, events that happen with the bot is offline can be an issue. so on startup I wanna list channels from both. I am just wondering how I could do this inside a function that can be called after both are connected
You could make a Boolean variable in your slack and set it to False and while it's False it won't run
When you startup your pycord bot make it connect to your slack and set the Boolean to true so that both your pycord and slack can run together in the same time
Also for this you would want to use an on_ready event
both can run at the same time already, all I need is a list of channels so I can compare the two
so I would need to list all channels without using a bot command basically
Then in the on_ready function
Add this code-
guild = client.get_guild(yourguildid)
channels = guild.text_channels
So once your bot starts up it will automatically get the guild's channels for u
And channels var will store the all the channels
Okay awesome