package main import ( "fmt" "os" "os/signal" "syscall" "github.com/bwmarrin/discordgo" )…
- User
package main
import ( "fmt" "os" "os/signal" "syscall"
code"github.com/bwmarrin/discordgo")
// Variables used for command line parameters
func main() { Token := "MTMwMTg2MzQwNjk4MjEzNTg0MQ.GrAz0i.8SM5pkptXfQDHaW_t9AuiIxFt8bCrC7xJcz08g" // Create a new Discord session using the provided bot token. dg, err := discordgo.New("Bot " + Token) if err != nil { fmt.Println("error creating Discord session,", err) return }
code// Register the messageCreate func as a callback for MessageCreate events. dg.AddHandler(messageCreate) // In this example, we only care about receiving message events. dg.Identify.Intents = discordgo.IntentsGuildMessages // Open a websocket connection to Discord and begin listening. err = dg.Open() if err != nil { fmt.Println("error opening connection,", err) return } // Wait here until CTRL-C or other term signal is received. fmt.Println("Bot is now running. Press CTRL-C to exit.") sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) <-sc // Cleanly close down the Discord session. dg.Close()}
// This function will be called (due to AddHandler above) every time a new // message is created on any channel that the authenticated bot has access to. func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
code// Ignore all messages created by the bot itself // This isn't required in this specific example but it's a good practice. if m.Author.ID == s.State.User.ID { return } // If the message is "ping" reply with "Pong!" fmt.Println(m.Content + " w ") 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!") } - Assistant
If you're not seeing any output from your bot's event handlers when messages are sent, there could be a few reasons why this might be happening. Here are some steps you can follow to debug and potentially fix the issue:
- User
добавь еще все нужные Intents
- Assistant
- User
error opening connection, websocket: close 4014: Disallowed intent(s)
- Assistant