generated from ACM-VIT/hacktoberfest-readme
-
Notifications
You must be signed in to change notification settings - Fork 17
/
listeners.go
59 lines (53 loc) · 1.93 KB
/
listeners.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
// guildMemberJoin sends welcome message when a new member joins the server.
func guildMemberJoin(s *discordgo.Session, memberAdd *discordgo.GuildMemberAdd) {
message := &discordgo.MessageSend{
Content: fmt.Sprintf("Welcome to the channel %s", memberAdd.Mention()),
Embeds: []*discordgo.MessageEmbed{{
Image: &discordgo.MessageEmbedImage{
URL: "https://thumbs.dreamstime.com/b/welcome-banner-shiny-colorful-confetti-vector-paper-illustration-welcome-banner-colorful-confetti-100006906.jpg",
Width: 10,
Height: 10,
},
}},
}
//Find all channels in the guild.
channels, _ := s.GuildChannels(memberAdd.GuildID)
for _, c := range channels {
// Send welcome message to general channel
// Send message to a text channel, if there is no general channel in the guild
if c.Name == "general" || c.Type == discordgo.ChannelTypeGuildText {
s.ChannelMessageSendComplex(c.ID, message)
return
}
}
fmt.Println("There is no text channel to send the welcome message.")
}
// guildMemberLeave sends goodbye message when a member leaves the server.
func guildMemberLeave(s *discordgo.Session, memberRemove *discordgo.GuildMemberRemove) {
message := &discordgo.MessageSend{
Content: fmt.Sprintf("Goodbye %s!", memberRemove.Mention()),
Embeds: []*discordgo.MessageEmbed{{
Image: &discordgo.MessageEmbedImage{
URL: "https://thumbs.dreamstime.com/b/goodbye-24589885.jpg",
Width: 10,
Height: 10,
},
}},
}
//Find all channels in the guild.
channels, _ := s.GuildChannels(memberRemove.GuildID)
for _, c := range channels {
// Send goodbye message to general channel
// Send message to a text channel, if there is no general channel in the guild
if c.Name == "general" || c.Type == discordgo.ChannelTypeGuildText {
s.ChannelMessageSendComplex(c.ID, message)
return
}
}
fmt.Println("There is no text channel to send the goodbye message.")
}