question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Looking for examples of sending messages without events

See original GitHub issue

Hi there, and thanks for the awesome library!

I was able to build the basic ping pong example within an hour, and everything works out of the gate. Great stuff. One thing that is stumping me, however, is that I am so far unable to just “send” a message without a particular event happening (not relying on the kord.on<> { } extension function.

I’m building a bot that is basically an external sentinel to a service I built, and I’d like the bot to be able to send an alert in a particular channel for devs whenever my service is not available, or when certain thresholds internal to my service are met. In that way, I don’t want to bot to respond to any particular message, I need it to be able to send its own messages whenever it wants.

I have the proper snowflake for the guild and channel and I’m trying to play with the Channel and MessageBehavior objects, but so far I haven’t been able to make it work.

I’m wondering if you have simple examples of that somewhere, or if you could maybe add one to the wiki. Cheers!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thunderbiscuitcommented, Dec 23, 2021

I think I’m following you, but for some reason it’s not quite clicking yet. I’m also not trying to pre-build anything, I mostly just want to fire up the bot once an hour and for it to post in our channel if something is wrong.

You say

the message is created and returned to you

Do you mean by that that the message is posted in the channel (and then stored in the variable?). If that is the case the error is on my configuration, as the bot runs but doesn’t post anything at the moment, using the following:

// say my channel's snowflake is 1234
val discordClient = Kord(discordToken)
discordClient.login()
val sentinelChannelSnowflake: Snowflake = Snowflake(1234)
val messageChannelBehaviour: MessageChannelBehavior? = discordClient.getChannelOf(id = sentinelChannelSnowflake)

messageChannelBehaviour?.createMessage {
    content = "Hello World!"
}
discordClient.logout()

Any idea where I might be going wrong?

EDIT: My problem was the login(). Got it working now. Cheers!

1reaction
HopeBaroncommented, Dec 23, 2021

Hello @thunderbiscuit,

You are not obliqued to send messages in events only. However, you need to get a MessageChannelBehavior at least. use our getChannelOf<MessageChannelBehavior> or getChannelOrNull<MessageChannelBehavior> on the Kord instance

same applies for a MessageBehavior you can use the channelOf function to switch the type of channel.

TL;DR: You need MessageChannelBehavior at least to send a message.

Note: depending on the version channelOf for Channels may be called of in older versions

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send message without command or event discord.py
From the documentation of discord.py, you first need to fetch the channel by its id and then you can send a message.
Read more >
Window.postMessage() - Web APIs | MDN
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it ...
Read more >
Sending messages - Slack API
Sending messages · Requesting the necessary permissions · Picking the right conversation · Composing your message · Publishing your message.
Read more >
Event-based campaigns let you automatically send messages ...
You can now use Amazon Pinpoint to set up campaigns that send messages (such as text messages, push notifications, and emails) to your...
Read more >
Messages Actions, Events, Audience, and Schedule
For example, if Chat is disabled in your Beacon, then Start Chat will not be an Action your Message can use. Action, Description....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found