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?
13 Replies
you need to wait some time even after receiving the ready event, before the cache is filled
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?
what even is a push event
also a bot can't be in a channel
in can be in threads, voice channels or guilds
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)
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
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
something like this should do:
if you want to get the channel by id, you can do this:
I guess id have to collect by guild first to get ALL guilds the bot is connected to before doing the filter?
back to your original code, you're trying to get the data before you've even logged in, which will never work
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
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?
The latter - something in my system will determine when to push the messages to all the text channels the bot is a part of
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