Browse Source

Docs update (#79)

* Update README.md

* Update 03-responding-to-slash-commands.md

* Update emoji.md
pull/1923/head
Nikon GitHub 4 years ago
parent
commit
a6154fdef7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 43 deletions
  1. +48
    -39
      README.md
  2. +5
    -3
      docs/guides/emoji/emoji.md
  3. +1
    -1
      docs/guides/slash-commands/03-responding-to-slash-commands.md

+ 48
- 39
README.md View File

@@ -32,52 +32,65 @@ webmilio's spin on the SlashCommandService branch, again the state of this is un
client.InteractionCreated += Client_InteractionCreated; client.InteractionCreated += Client_InteractionCreated;


... ...
private async Task Client_InteractionCreated(SocketInteraction arg)
private async Task Client_InteractionCreated(SocketInteraction interaction)
{ {
switch (arg.Type) // We want to check the type of this interaction
// Checking the type of this interaction
switch (interaction)
{ {
//Slash commands
case InteractionType.ApplicationCommand:
await MySlashCommandHandler(arg);
// Slash commands
case SocketSlashCommand commandInteraction:
await MySlashCommandHandler(commandInteraction);
break; break;
//Button clicks/selection dropdowns
case InteractionType.MessageComponent:
await MyMessageComponentHandler(arg);
// Button clicks/selection dropdowns
case SocketMessageComponent componentInteraction:
await MyMessageComponentHandler(componentInteraction);
break; break;
//Unused
case InteractionType.Ping:
break;
//Unknown/Unsupported
// Unused or Unknown/Unsupported
default: default:
Console.WriteLine("Unsupported interaction type: " + arg.Type);
break; break;
} }
} }
``` ```


### Handling button clicks and selection dropdowns
### Simple handling slash commands
```cs ```cs
private async Task MyMessageComponentHandler(SocketInteraction arg)
private async Task MySlashCommandHandler(SocketSlashCommand interaction)
{
// Checking command name
if (interaction.Data.Name == "ping")
{
// Respond to interaction with message.
// You can also use "ephemeral" so that only the original user of the interaction sees the message
await interaction.RespondAsync($"Pong!", ephemeral: true);
// Also you can followup with a additional messages, which also can be "ephemeral"
await interaction.FollowupAsync($"PongPong!", ephemeral: true);
}
}
```

### Simple handling button clicks and selection dropdowns
```cs
private async Task MyMessageComponentHandler(SocketMessageComponent interaction)
{ {
// Parse the arg
var parsedArg = (SocketMessageComponent) arg;
// Get the custom ID // Get the custom ID
var customId = parsedArg.Data.CustomId;
var customId = interaction.Data.CustomId;
// Get the user // Get the user
var user = (SocketGuildUser) arg.User;
var user = (SocketGuildUser) interaction.User;
// Get the guild // Get the guild
var guild = user.Guild; var guild = user.Guild;
// Respond with the update message response type. This edits the original message if you have set AlwaysAcknowledgeInteractions to false.
// You can also use "ephemeral" so that only the original user of the interaction sees the message
await parsedArg.RespondAsync($"Clicked {parsedArg.Data.CustomId}!", type: InteractionResponseType.UpdateMessage, ephemeral: true);
// Respond with the update message. This edits the message which this component resides.
await interaction.UpdateAsync(msgProps => msgProps.Content = $"Clicked {interaction.Data.CustomId}!");
// You can also followup with a second message
await parsedArg.FollowupAsync($"Clicked {parsedArg.Data.CustomId}!", type: InteractionResponseType.ChannelMessageWithSource, ephemeral: true);
// Also you can followup with a additional messages
await interaction.FollowupAsync($"Clicked {interaction.Data.CustomId}!", ephemeral: true);
//If you are using selection dropdowns, you can get the selected label and values using these:
var selectedLabel = ((SelectMenu) parsedArg.Message.Components.First().Components.First()).Options.FirstOrDefault(x => x.Value == parsedArg.Data.Values.FirstOrDefault())?.Label;
var selectedValue = parsedArg.Data.Values.First();
// If you are using selection dropdowns, you can get the selected label and values using these
var selectedLabel = ((SelectMenu) interaction.Message.Components.First().Components.First()).Options.FirstOrDefault(x => x.Value == interaction.Data.Values.FirstOrDefault())?.Label;
var selectedValue = interaction.Data.Values.First();
} }
``` ```


@@ -97,18 +110,14 @@ var builder = new ComponentBuilder()
.WithSelectMenu(new SelectMenuBuilder() .WithSelectMenu(new SelectMenuBuilder()
.WithCustomId("id_2") .WithCustomId("id_2")
.WithPlaceholder("This is a placeholder") .WithPlaceholder("This is a placeholder")
.WithOptions(new List<SelectMenuOptionBuilder>()
{
new SelectMenuOptionBuilder()
.WithLabel("Option A")
.WithEmote(Emote.Parse("<:evanpog:810017136814194698>"))
.WithDescription("Evan pog champ")
.WithValue("value1"),
new SelectMenuOptionBuilder()
.WithLabel("Option B")
.WithDescription("Option B is poggers")
.WithValue("value2")
}));
.AddOption(
label: "Option",
value: "value1",
description: "Evan pog champ",
emote: Emote.Parse("<:evanpog:810017136814194698>")
)
.AddOption("Option B", "value2", "Option B is poggers");
await Context.Channel.SendMessageAsync("Test selection!", component: builder.Build()); await Context.Channel.SendMessageAsync("Test selection!", component: builder.Build());
``` ```




+ 5
- 3
docs/guides/emoji/emoji.md View File

@@ -46,14 +46,16 @@ form; this can be obtained in several different ways.
### Emoji Declaration ### Emoji Declaration


After obtaining the Unicode representation of the emoji, you may After obtaining the Unicode representation of the emoji, you may
create the @Discord.Emoji object by passing the string into its
create the @Discord.Emoji object by passing the string with unicode into its
constructor (e.g. `new Emoji("👌");` or `new Emoji("\uD83D\uDC4C");`). constructor (e.g. `new Emoji("👌");` or `new Emoji("\uD83D\uDC4C");`).


Your method of declaring an @Discord.Emoji should look similar to Your method of declaring an @Discord.Emoji should look similar to
this: this:

[!code-csharp[Emoji Sample](samples/emoji-sample.cs)] [!code-csharp[Emoji Sample](samples/emoji-sample.cs)]


Also you can use `Emoji.Parse()` or `Emoji.TryParse()` methods
for parsing emojis from strings like `:heart:`, `<3` or `❤`.

[FileFormat.Info]: https://www.fileformat.info/info/emoji/list.htm [FileFormat.Info]: https://www.fileformat.info/info/emoji/list.htm


## Emote ## Emote
@@ -97,4 +99,4 @@ this:
## Additional Information ## Additional Information


To learn more about emote and emojis and how they could be used, To learn more about emote and emojis and how they could be used,
see the documentation of @Discord.IEmote.
see the documentation of @Discord.IEmote.

+ 1
- 1
docs/guides/slash-commands/03-responding-to-slash-commands.md View File

@@ -45,6 +45,6 @@ Let's try this out!


Let's go over the response types quickly, as you would only change them for style points :P Let's go over the response types quickly, as you would only change them for style points :P


> After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using `ChannelMessageWithSource` or you can choose to send a deferred response with `DeferredChannelMessageWithSource`. If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response. You can read more about response types [here](https://discord.com/developers/docs/interactions/slash-commands#interaction-response)
> After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using `RespondAsync()` or you can choose to send a deferred response with `DeferAsync()`. If choosing a deferred response, the user will see a loading state for the interaction, and you'll have up to 15 minutes to edit the original deferred response using `ModifyOriginalResponseAsync()`. You can read more about response types [here](https://discord.com/developers/docs/interactions/slash-commands#interaction-response)


This seems to be working! Next, we will look at parameters for slash commands. This seems to be working! Next, we will look at parameters for slash commands.

Loading…
Cancel
Save