Skip to content

Commit

Permalink
Example for user context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorLap2006 committed Aug 6, 2021
1 parent 2f3aefa commit dd1f888
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/context_menus/main.go
Expand Up @@ -43,6 +43,10 @@ func searchLink(message, format, sep string) string {

var (
commands = []discordgo.ApplicationCommand{
{
Name: "rickroll-em",
Type: discordgo.UserApplicationCommand,
},
{
Name: "google-it",
Type: discordgo.MessageApplicationCommand,
Expand All @@ -65,6 +69,38 @@ var (
},
}
commandsHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"rickroll-em": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Operation rickroll has begun",
Flags: 1 << 6,
},
})
if err != nil {
panic(err)
}

ch, err := s.UserChannelCreate(
i.ApplicationCommandData().TargetID,
)
if err != nil {
_, err = s.FollowupMessageCreate(*AppID, i.Interaction, true, &discordgo.WebhookParams{
Content: fmt.Sprintf("Mission failed. Cannot send a message to this user: %q", err.Error()),
Flags: 1 << 6,
})
if err != nil {
panic(err)
}
}
_, err = s.ChannelMessageSend(
ch.ID,
fmt.Sprintf("%s sent you this: https://youtu.be/dQw4w9WgXcQ", i.Member.Mention()),
)
if err != nil {
panic(err)
}
},
"google-it": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Expand Down

0 comments on commit dd1f888

Please sign in to comment.