package discord import ( "fmt" "net/http" "strings" "git.birbmc.com/Etzelia/go-serverapi" ) func init() { commands = append(commands, &command{ staffOnly: true, name: "broadcast", validate: func(cmd commandInit) bool { return isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles) }, run: func(cmd commandInit) (string, error) { args := strings.Fields(cmd.message.Content) if len(args) < 2 { return "This command requires a message to broadcast", nil } message := strings.Join(args[1:], " ") broadcast := serverapi.Broadcast{ From: cmd.message.Author.Username, Message: message, } status, err := cmd.sapiClient.Broadcast(broadcast) if err != nil { return "", err } if status != http.StatusOK { return fmt.Sprintf("ServerAPI returned status %d when trying to broadcast.", status), nil } return "Broadcast sent!", nil }, help: "Send an in-game broadcast", }) }