本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.ChannelMessageSend方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.ChannelMessageSend方法的具体用法?Golang Session.ChannelMessageSend怎么用?Golang Session.ChannelMessageSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.ChannelMessageSend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Message
// Message receives a Message struct and sends it to appropriate channels
func Message(s *discordgo.Session, m *types.Message) error {
message := strings.Join(m.Payload, "\n")
var channels []string
var dchannels []*discordgo.Channel
var err error
c := config.Get()
if m.Prefix != "" {
message = fmt.Sprintf("%s: %s", m.Prefix, message)
}
if m.Channels[0] == "*" {
dchannels, err = s.GuildChannels(c.Guild)
if err != nil {
return err
}
//errhandler.Handle(err)
for _, chann := range dchannels {
channels = append(channels, chann.ID)
}
} else {
channels = m.Channels
}
log.Debugf("%s\n", len(channels))
for _, channel := range channels {
s.ChannelMessageSend(channel, message)
}
return nil
}
示例2: sendMessage
func sendMessage(sess *discordgo.Session, message string) {
channelid := fetchPrimaryTextChannelID(sess)
logInfo("SENDING MESSAGE:", message)
retryOnBadGateway(func() error {
_, err := sess.ChannelMessageSend(channelid, message)
return err
})
}
示例3: bdLinks
func bdLinks(s *discordgo.Session, id string) {
resp, err := http.Get("https://betterdiscord.net/home/")
checkErr(err)
bytes, err := ioutil.ReadAll(resp.Body)
checkErr(err)
rx := regexp.MustCompile(`<a href="(.*.zip)`)
mm := rx.FindAllStringSubmatch(string(bytes), 2)
s.ChannelMessageSend(id,
fmt.Sprintf("\n`OSX:` %s\n`Windows:` %s", mm[1][1], mm[0][1]))
}
示例4: onGuildCreate
func onGuildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
if event.Guild.Unavailable != nil {
return
}
for _, channel := range event.Guild.Channels {
if channel.ID == event.Guild.ID {
s.ChannelMessageSend(channel.ID, "**AIRHORN BOT READY FOR HORNING. TYPE `!AIRHORN` WHILE IN A VOICE CHANNEL TO ACTIVATE**")
return
}
}
}
示例5: guildCreate
// This function will be called (due to AddHandler above) every time a new
// guild is joined.
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
if event.Guild.Unavailable != nil {
return
}
for _, channel := range event.Guild.Channels {
if channel.ID == event.Guild.ID {
_, _ = s.ChannelMessageSend(channel.ID, "Airhorn is ready! Type !airhorn while in a voice channel to play a sound.")
return
}
}
}
示例6: checkForPermissions
func checkForPermissions(s *discordgo.Session,
channelID string, roleID []string) bool {
var ok bool
if len(roleID) > 0 {
_, ok = adminIds[roleID[0]]
if ok == true {
return ok
}
}
s.ChannelMessageSend(channelID, fmt.Sprintf("Insuficient permissions"))
return ok
}
示例7: onGuildCreate
// the below method is invoked when the Discord Websocket API transmits
// a 'guildCreate' event to the bot
func onGuildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
logrus.WithFields(logrus.Fields{
"guildId": event.ID,
"guildName": event.Name,
"joinedAt": event.JoinedAt,
}).Debug("Received guild create event from Discord Websocket API.")
// send greet message to the appropriate general/lobby channel
for _, channel := range event.Guild.Channels {
if channel.ID == event.Guild.ID {
s.ChannelMessageSend(channel.ID, "Pokemon Discord is ready for use! Type `!setTeam [name]` to set your Pokemon GO team.")
}
}
}
示例8: bannedUsers
func bannedUsers(s *discordgo.Session, m *discordgo.MessageCreate) {
pgDb := dbConn()
rows, err := pgDb.Query("SELECT name, time_stamp, duration from bans")
checkErr(err)
for rows.Next() {
var time_stamp, duration int64
var name string
rows.Scan(&name, &time_stamp, &duration)
s.ChannelMessageSend(m.ChannelID,
fmt.Sprintf("```\n%s %s\n```", name,
time.Unix(time_stamp+duration, 0).Format("2006-01-02 15:04")))
}
rows.Close()
pgDb.Close()
}
示例9: messageCreate
// This function will be called (due to AddHandler above) every time a new
// message is created on any channel that the autenticated bot has access to.
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
if m.Author.ID == BotID {
return
}
// If the message is "ping" reply with "Pong!"
if m.Content == "ping" {
_, _ = s.ChannelMessageSend(m.ChannelID, "Pong!")
}
// If the message is "pong" reply with "Ping!"
if m.Content == "pong" {
_, _ = s.ChannelMessageSend(m.ChannelID, "Ping!")
}
}
示例10: handleBotControlMessages
// Handles bot operator messages, should be refactored (lmao)
func handleBotControlMessages(s *discordgo.Session, m *discordgo.MessageCreate, parts []string, g *discordgo.Guild) {
if scontains(parts[1], "status") {
displayBotStats(m.ChannelID)
} else if scontains(parts[1], "stats") {
if len(m.Mentions) >= 2 {
displayUserStats(m.ChannelID, utilGetMentioned(s, m).ID)
} else if len(parts) >= 3 {
displayUserStats(m.ChannelID, parts[2])
} else {
displayServerStats(m.ChannelID, g.ID)
}
} else if scontains(parts[1], "bomb") && len(parts) >= 4 {
airhornBomb(m.ChannelID, g, utilGetMentioned(s, m), parts[3])
} else if scontains(parts[1], "aps") {
s.ChannelMessageSend(m.ChannelID, ":ok_hand: give me a sec m8")
go calculateAirhornsPerSecond(m.ChannelID)
}
}
示例11: handleExternalCommand
func handleExternalCommand(status int, command []string, pluginDir string, plugin *types.Plugin, s *discordgo.Session, m *discordgo.Message) (handled bool) {
//s := conn.Get()
// always send the event to messageDelete
if status == globals.MATCH || status == globals.HELP {
messageDelete(s, m.ChannelID, m.ID)
handled = true
}
if status == globals.MATCH && plugin.Type == "simple" {
output, err := plugins.Exec(pluginDir, plugin.Filename, command[1:])
if err == nil {
s.ChannelMessageSend(m.ChannelID, string(output))
}
} else if (status == globals.MATCH || status == globals.HELP) && plugin.Type == "json" {
var message types.PluginMessage
if status == globals.MATCH {
message.Arguments = command[1:]
} else if status == globals.HELP {
message.Arguments = []string{}
}
message.User = m.Author.Username
message.Channel = m.ChannelID
output, err := plugins.ExecJSON(pluginDir, plugin.Filename, &message)
if err == nil {
handleJSONPlugin(plugin.Name, output, s)
} else {
log.Warning("Could not exec json plugin %s", plugin.Name)
}
} else if status == globals.HELP {
output, err := plugins.Exec(pluginDir, plugin.Filename, []string{})
if err == nil {
s.ChannelMessageSend(m.ChannelID, string(output))
}
}
return
}
示例12: onGuildMemberAdd
// the below method is invoked when the Discord Websocket API transmits
// a 'guildMemberAdd' event to the bot
func onGuildMemberAdd(s *discordgo.Session, event *discordgo.GuildMemberAdd) {
logrus.WithFields(logrus.Fields{
"guildId": event.GuildID,
"joinedAt": event.JoinedAt,
"userId": event.User.ID,
"username": event.User.Username,
}).Debug("Received guild member add event from Discord Websocket API.")
guild, err := s.Guild(event.GuildID)
if err != nil {
logrus.WithFields(logrus.Fields{
"guildId": event.GuildID,
"capturedError": err,
}).Error("Could not retrieve guild object from identifier.")
return
}
primaryChan, err := findPrimaryChannelInGuild(s, &event.GuildID)
if err != nil {
logrus.WithFields(logrus.Fields{
"userId": event.User.ID,
"guildId": event.GuildID,
"capturedError": err,
}).Error("Could not determine primary channel for guild.")
return
}
// create a private messaging channel between the bot and the new guild member
privChan, err := s.UserChannelCreate(event.User.ID)
if err != nil {
logrus.WithFields(logrus.Fields{
"userId": event.User.ID,
"capturedError": err,
}).Error("Could not create channel between bot and user.")
return
}
// send greet message to new guild member
s.ChannelMessageSend(privChan.ID, "Welcome to "+guild.Name+"! We recommend setting your Pokemon GO team to grant access to team-only channels. To do so, type `!setTeam [name]` into the #"+primaryChan.Name+" text channel to set your Pokemon GO team. Available team names are: 'valor' (red), 'mystic' (blue) and 'instinct' (yellow).")
}
示例13: onMessageCreate
// the below method is invoked when the Discord Websocket API transmits
// a 'messageCreate' event to the bot
func onMessageCreate(s *discordgo.Session, event *discordgo.MessageCreate) {
logrus.WithFields(logrus.Fields{
"authorId": event.Author.ID,
"authorUsername": event.Author.Username,
"channelId": event.ChannelID,
"timestamp": event.Timestamp,
"content": event.Content,
}).Debug("Received message create event from Discord Websocket API.")
// do not take action if the author of the message is ourself
if s.State.Ready.User.ID == event.Author.ID {
return
}
// ensure the message was not received via direct message
currChannel, err := s.Channel(event.ChannelID)
if err != nil {
logrus.WithFields(logrus.Fields{
"channelId": event.ChannelID,
"capturedError": err,
}).Error("Could not retrieve channel object from identifier.")
return
}
if currChannel.IsPrivate {
s.ChannelMessageSend(event.ChannelID, "Hi! I don't respond to commands sent through direct message, as I cannot tell what Discord server you are trying to set on! Please send me a message in the appropriate text channel on a Discord server to try again.")
return
}
// convert the text to lowercase to avoid case-sensitivity issues
lowerContent := strings.ToLower(event.ContentWithMentionsReplaced())
if strings.HasPrefix(lowerContent, "!setteam ") {
givenTeamName := lowerContent[9:]
go handleTeamSet(s, &givenTeamName, &event.Author.ID, &event.ChannelID)
}
}
示例14: handleInternalCommand
func handleInternalCommand(status int, command []string, s *discordgo.Session, m *discordgo.Message) (handled bool) {
if status == globals.MATCH || status == globals.HELP {
messageDelete(s, m.ChannelID, m.ID)
handled = true
}
if status == globals.MATCH {
switch {
case command[1] == "plugins":
s.ChannelMessageSend(m.ChannelID, printHelp())
case command[1] == "reload":
plugins.Register()
s.ChannelMessageSend(m.ChannelID, "Digo Reloaded")
default:
s.ChannelMessageSend(m.ChannelID, printHelp())
}
} else if status == globals.HELP {
s.ChannelMessageSend(m.ChannelID, printHelp())
}
return
}
示例15: manualUnban
func manualUnban(s *discordgo.Session, channelID string,
roleID []string, arr []string) {
if checkForPermissions(s, channelID, roleID) &&
len(arr) == 3 && len(arr[2]) == 21 {
arr[2] = arr[2][2 : len(arr[2])-1]
pgDb := dbConn()
tx, err := pgDb.Begin()
checkErr(err)
user, _ := s.User(arr[2])
name := user.Username
rows, err := tx.Query(
"SELECT id, guild_id, role_id FROM bans WHERE name = $1", name)
checkErr(err)
flag := false
for rows.Next() {
flag = true
var id, guild_id, role_id string
rows.Scan(&id, &guild_id, &role_id)
if len(guild_id) != 0 {
rows.Close()
_, err = tx.Exec("DELETE FROM bans WHERE id = $1", id)
checkErr(err)
s.GuildMemberEdit(guild_id, arr[2], []string{role_id})
s.ChannelMessageSend(channelID,
fmt.Sprintf("User %s has been unbanned", name))
break
}
}
tx.Commit()
pgDb.Close()
if flag == false {
s.ChannelMessageSend(channelID,
fmt.Sprintf("User %s is not banned", name))
}
} else {
s.ChannelMessageSend(channelID,
fmt.Sprintf("Please check the parameters"))
}
}