-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ken with discordgo.InteractionCreate #15
Comments
Hey, can you show me a specific example of your code? That would be very helpful for me so that I can understand the context about what's happening. :) |
Yeah, of course. First my bot listens to all channels on server (messageCreate Discord API event), when an user sends a specific message, the bot reply with a missage that contains a component with two buttons. I've created a new listener to If I remove listener to new interactions, ken works perfectly. Here is some code: func (l *ListenerInteractionCreate) Handler(s *discordgo.Session, e *discordgo.InteractionCreate) {
fmt.Println(e.Interaction)
// On this example I'm just checking if user clicked on a button, but later will check if custom id matches with database record.
if e.MessageComponentData().ComponentType == 2 {
err := s.InteractionRespond(e.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Title: "Hello World!",
},
},
},
})
if err != nil {
fmt.Println(err)
}
}
} |
Ah yo, that's unfortunate. I actually didn't tested this use case before. You can actually use ken to handle message components for you even on messages sent by your bot without using ken's framework using |
Thank you very much. I'm just starting with Go and Ken, can you send a small example of how can I implement message handle using ken, please? |
Currently, I have no direct example for that in the examples of the package, but here you can see how I am using it to attach and handle message components for a role selection command in my Discord bot. https://github.com/zekroTJA/shinpuru/blob/master/internal/slashcommands/roleselect.go#L149 |
Thanks! I'll try to do this. One last question, please... In this example you created a slash command that will send components buttons, there is any way to don't create new command, just listen to button interactions? |
Hi, I'm facing an issue when implementing solution that you suggested. If I restart the bot, I lose handler for buttons that I appended to message using |
@andrebrito16 Sorry for the very late response. Yeah, it is possible to re-attach event handlers on an already sent messasge. I am actually using this in the role select feature of my own discord bot. Here, in the ready event listener, I am looking for roleselect entries in my database and then attaching them to the messages stored in the database.
It works because the The code example is a bit complicated to be honest, but I hope it helps your problem (if it is still relevant). If you have problems, feel free to hit me up again. :) |
Hi, I'm starting to use Ken on a new project. But when I register a listener to
discordgo.InteractionCreate
events I gotpanic: MessageComponentData called on interaction of type ApplicationCommand
. There is any way to continue using ken and also listen to InteractionCreate?The text was updated successfully, but these errors were encountered: