-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update dasgo fix message components usage add message components half example fix RateLimitHashFuncs map
- Loading branch information
1 parent
064e1a0
commit 349d456
Showing
15 changed files
with
1,252 additions
and
745 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Example: Send a Message Component | ||
|
||
This example sends message components to a channel. | ||
|
||
_This example is UNFINISHED: User input to message components are handled using [interactions](/_examples/command/)._ | ||
|
||
## Setup | ||
|
||
**You must create a Discord Application in the [Discord Developer Portal](https://discord.com/developers/docs/getting-started#creating-an-app) to receive your Bot Token.** | ||
|
||
### Environment Variables | ||
|
||
Assign an environment variable in the command line you will be running the program from. | ||
|
||
#### Windows | ||
|
||
``` | ||
set TOKEN=value | ||
``` | ||
|
||
#### Mac/Linux | ||
|
||
``` | ||
export TOKEN=value | ||
``` | ||
|
||
**NEVER SHOW YOUR TOKEN TO THE PUBLIC.** | ||
|
||
### Flags | ||
|
||
This example uses [command line flags](https://pkg.go.dev/flag) to input the channel and message content. | ||
|
||
``` | ||
> components -h | ||
Usage of send: | ||
-c string | ||
Set the channel (ID) the message components will be sent to using -c. | ||
``` | ||
|
||
## Usage | ||
|
||
Use `go build` to build the executable binary. Use `components` to run it from the command line. | ||
|
||
_NOTE: Get the Channel ID by enabling **Developer Mode** from the settings of your account, then right clicking any channel._ | ||
|
||
``` | ||
components -c 1041179872518737990 | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
"github.com/switchupcb/disgo" | ||
) | ||
|
||
// Environment Variables. | ||
var ( | ||
// token represents the bot's token. | ||
token = os.Getenv("TOKEN") | ||
) | ||
|
||
// Command Line Flags. | ||
var ( | ||
channelID = flag.String("c", "", "Set the channel (ID) the message components will be sent to using -c.") | ||
) | ||
|
||
func main() { | ||
// enable the logger for the API Wrapper. | ||
// zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||
|
||
// parse the command line flags. | ||
flag.Parse() | ||
|
||
// ensure that the program has the necessary data to succeed. | ||
if token == "" { | ||
log.Println("The bot's token must be set, but is currently empty.") | ||
|
||
return | ||
} | ||
|
||
if *channelID == "" { | ||
log.Println("The channel to send the message to is not set.") | ||
flag.Usage() | ||
|
||
return | ||
} | ||
|
||
// create a new Bot Client with the information required to send a request. | ||
bot := &disgo.Client{ | ||
Authentication: disgo.BotToken(token), // or BearerToken("TOKEN") | ||
Config: disgo.DefaultConfig(), | ||
} | ||
|
||
// ensure that the bot has access to the channel. | ||
// | ||
// This is useful for the validation of this program, but unnecessary. | ||
getChannelRequest := disgo.GetChannel{ChannelID: *channelID} | ||
_, err := getChannelRequest.Send(bot) | ||
if err != nil { | ||
log.Printf("error occurred getting channel %q: %v", *channelID, err) | ||
|
||
return | ||
} | ||
|
||
// send an Action Row (containing a Button) to the channel. | ||
createMessageRequestActionRowButton := &disgo.CreateMessage{ //nolint:exhaustruct | ||
ChannelID: *channelID, | ||
Content: disgo.Pointer("This is an Action Row (containing a Button)."), | ||
Components: []disgo.Component{ | ||
&disgo.ActionRow{ | ||
Type: disgo.FlagComponentTypeActionRow, | ||
Components: []disgo.Component{ | ||
&disgo.Button{ | ||
Type: disgo.FlagComponentTypeButton, | ||
Style: disgo.FlagButtonStyleRED, | ||
Label: disgo.Pointer("Button Label."), | ||
Emoji: nil, | ||
CustomID: disgo.Pointer("example-button"), | ||
URL: nil, | ||
Disabled: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
message, err := createMessageRequestActionRowButton.Send(bot) | ||
if err != nil { | ||
log.Printf("error occurred sending a message to channel %q: %v", *channelID, err) | ||
|
||
return | ||
} | ||
|
||
log.Printf("Successfully sent message with ID %q", message.ID) | ||
|
||
// send an Action Row (containing a Select Menu) to the channel. | ||
createMessageRequestActionRowSelectMenu := &disgo.CreateMessage{ //nolint:exhaustruct | ||
ChannelID: *channelID, | ||
Content: disgo.Pointer("This is an Action Row (containing a String Select Menu)."), | ||
Components: []disgo.Component{ | ||
&disgo.ActionRow{ | ||
Type: disgo.FlagComponentTypeActionRow, | ||
Components: []disgo.Component{ | ||
&disgo.SelectMenu{ | ||
Type: disgo.FlagComponentTypeStringSelect, | ||
CustomID: "example-select-menu", | ||
Placeholder: disgo.Pointer("Select an option."), | ||
Options: []disgo.SelectMenuOption{ | ||
{ | ||
Label: "Yes", | ||
Value: "yes", | ||
Description: disgo.Pointer("Yessir."), | ||
Emoji: nil, | ||
Default: nil, | ||
}, | ||
{ | ||
Label: "No", | ||
Value: "no", | ||
Description: disgo.Pointer("Nope!"), | ||
Emoji: nil, | ||
Default: nil, | ||
}, | ||
}, | ||
MinValues: nil, | ||
MaxValues: nil, | ||
Disabled: nil, | ||
ChannelTypes: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
message, err = createMessageRequestActionRowSelectMenu.Send(bot) | ||
if err != nil { | ||
log.Printf("error occurred sending a message to channel %q: %v", *channelID, err) | ||
|
||
return | ||
} | ||
|
||
log.Printf("Successfully sent message with ID %q", message.ID) | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.