#Slash Command
1 messages · Page 1 of 1 (latest)
and then when handling the button click:
- you get the number of the page from button's custom id
- do a
IComponentInteraction.UpdateAsync, updating:- the embed
- buttons with updated page numbers
a small pseudocode example:
private ComponentBuilder GetPageSwitchComponents(int page, int maxPage)
{
var cmp = new ComponentBuilder();
if (page <= 1)
cmp.WithButton("Previous", $"yesPageSwitch_1", style: ButtonStyle.Secondary, disabled: true);
else
cmp.WithButton("Previous", $"yesPageSwitch_{page - 1}", style: ButtonStyle.Primary);
if (page >= maxPage)
cmp.WithButton("Next", $"yesPageSwitch_{maxPage}", style: ButtonStyle.Secondary, disabled: true);
else
cmp.WithButton("Next", $"yesPageSwitch_{page + 1}", style: ButtonStyle.Primary);
return cmp;
}
[SlashCommand("yes", "1337")]
public async Task YesAsync()
{
await RespondAsync("we are on page 1", components: GetPageSwitchComponents(1, 69).Build());
}
[ComponentInteraction("yesPageSwitch_*")]
public async Task YesPageSwitchAsync(int page)
{
var interaction = (IComponentInteraction)Context.Interaction;
await interaction.UpdateAsync(x => {
x.Content = $"we are on page {page}";
x.Components = GetPageSwitchComponents(page, 69);
});
}