turns-00043.parquet:16821
fc39cad5367bbffda9ade0a3
turn 1/2gpt-4o-2024-08-06EnglishRussia568 words
degenerate_repetitionAbsentFinal dense release
USER
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"os"
"os/signal"
"strings"
"syscall"
)
const (
prefix = "+"
prefix1 = "-"
prefix2 = "!"
)
var (
whiteList = map[string]bool{
"1184449624950460488": true,
"683970164861042690": true,
}
allowedChannels = map[string]bool{
"1087629024139943936": true,
"1174286575878815855": true,
}
)
func main() {
token := "MTMwMTg2MzQwNjk4MjEzNTg0MQ.GrAz0i.8SM5pkptXfQDHaW_t9AuiIxFt8bCrC7xJcz08g"
dg, err := discordgo.New("Bot " + token)
if err != nil {
panic(err)
}
defer func() {
r := recover()
if r != nil {
fmt.Println(r)
}
}()
dg.AddHandler(messageCreate)
err = dg.Open()
if err != nil {
panic(err)
}
defer dg.Close()
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
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if strings.HasPrefix(m.Content, prefix) || strings.HasPrefix(m.Content, prefix1) || strings.HasPrefix(m.Content, prefix2) {
parts := strings.Split(m.Content, " ")
command := parts[0]
switch command {
case prefix2 + "ss":
fmt.Println("eregergegr")
}
}
}
добавь слеш команду /command которая будет прислать embed ASSISTANT
To add a slash command in your Discord bot using the `discordgo` package, you'll need to define an application command and register it with Discord's API. Slash commands require some additional setup compared to traditional prefixed commands, but they provide a robust and user-friendly interface.
Here is an updated version of your code with a `/command` slash command that sends an embed message:
```go
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"os"
"os/signal"
"syscall"
)
var (
whiteList = map[string]bool{
"1184449624950460488": true,
"683970164861042690": true,
}
allowedChannels = map[string]bool{
"1087629024139943936": true,
"1174286575878815855": true,
}
)
func main() {
token := "YOUR_BOT_TOKEN"
dg, err := discordgo.New("Bot " + token)
if err != nil {
panic(err)
}
defer func() {
r := recover()
if r != nil {
fmt.Println(r)
}
}()
dg.AddHandler(messageCreate)
dg.AddHandler(interactionCreate)
err = dg.Open()
if err != nil {
panic(err)
}
defer dg.Close()
registerCommands(dg)
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
}
// registerCommands registers the slash commands with Discord.
func registerCommands(s *discordgo.Session) {
_, err := s.ApplicationCommandCreate(s.State.User.ID, "", &discordgo.ApplicationCommand{
Name: "command",
Description: "Send an embed message",
})
if err != nil {
fmt.Printf("Cannot create command: %v", err)
}
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
// Other message handling logic
}
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
if i.ApplicationCommandData().Name == "command" {
embed := &discordgo.MessageEmbed{
Title: "Hello, World!",
Description: "This is an Embed message sent by the bot.",
Color: 0x00ff00, // Green color
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{embed},
},
})
}
}
```
### Explanation
1. **Slash Command Registration**: The `/command` slash command is registered with the `ApplicationCommandCreate` function. This command is set globally due to the empty `GuildID` parameter.
2. **Interaction Handler**: The `interactionCreate` handler listens for interactions triggered by slash commands. When your `/command` is invoked, it responds with an embed message.
3. **Embed**: The embed message has been added using a `discordgo.MessageEmbed` struct, which allows you to specify the contents and appearance of the embed (e.g., title, description, color).
### Important Notes
- **Token Security**: Make sure never to expose your bot token publicly. Replace `"YOUR_BOT_TOKEN"` with your actual Discord bot token when running the bot.
- **Permissions**: The bot requires permission to read messages and respond, so ensure it has the necessary permissions in your guilds.
- **Application Commands**: It may take a few minutes for slash commands to appear in Discord after being registered.