K
Kord3mo ago
ieatfries

How to generate push messages in channels?

Hey there, new to Kotlin/Kord in general. I'm trying to push messages to specific channels that my bot is in. The example in the github makes this esay becasue the channel is ready already. When I try to do something similar to the screenshot, the it.channelIds are always empty but I see the bot existing in the channel. What's the best way to approach something like this?
No description
13 Replies
SchlaubiBus
SchlaubiBus3mo ago
you need to wait some time even after receiving the ready event, before the cache is filled
ieatfries
ieatfriesOP3mo ago
I think I'm more interested in ONLY generating a push event. So an ideal workflow would be something like 1. Find out which channel's my bot is in. 2. Do a create message event at a timed interval using the channel id. It looks like at some point I might have to store this info in a db which is fine I was able to do this when just using the rest api (/api/channels/<channel_id>/message) and using the embed is there a "Kord" way of doing this?
SchlaubiBus
SchlaubiBus3mo ago
what even is a push event also a bot can't be in a channel in can be in threads, voice channels or guilds
ieatfries
ieatfriesOP3mo ago
Why not? I have a bot thats inside a text channel right now And i got it to just send a message via the discord api using the base rest client Sorry maybe a push event is wrong terminology. Realistically i want to be able to send a message with the bot at some specified time (which is to be determined by my backend)
LustigerLurch
LustigerLurch3mo ago
it's just a technicality - channels in a guild just exist and you need a permission to be able to view them and also to send messages in them
ieatfries
ieatfriesOP3mo ago
Right but each time i try to loop through the channels in the guild prop it ends up empty. Furthermore is there an example of how when I get the channel Id how to be able to actually create a new message? The example on github is easy because the MessageChannel clsss already has a way to do it
LustigerLurch
LustigerLurch3mo ago
something like this should do:
guild.channels
.filterIsInstance<MessageChannel>()
.collect { channel ->
channel.createMessage { content = "text" }
}
guild.channels
.filterIsInstance<MessageChannel>()
.collect { channel ->
channel.createMessage { content = "text" }
}
if you want to get the channel by id, you can do this:
val channel = kord.getChannelOf<MessageChannel>(id)
val channel = kord.getChannelOf<MessageChannel>(id)
ieatfries
ieatfriesOP3mo ago
I guess id have to collect by guild first to get ALL guilds the bot is connected to before doing the filter?
Thiakil
Thiakil3mo ago
back to your original code, you're trying to get the data before you've even logged in, which will never work
ieatfries
ieatfriesOP3mo ago
So would the idea be to run another coroutine? Would the other coroutine have scope to the kord object? Kotlin noob Or is it literally just a matter of logging in then doing it
Thiakil
Thiakil3mo ago
not sure that's the correct understanding of coroutines, but it all depends on what you need to do do you need gateway events at all? (e.g listening for new messages with specific contents) or are you just sending messages based on some external input/timing?
ieatfries
ieatfriesOP3mo ago
The latter - something in my system will determine when to push the messages to all the text channels the bot is a part of
Thiakil
Thiakil3mo ago
Sounds like a webhook is more appropriate, that's the only way to be part of a channel, rather than just having permission to post in one
Want results from more Discord servers?
Add your server