This is an addon for the Discord API Wrapper Discord.Net.
- Creating dynamic embed pages.
- Creating dynamic multi buttons.
- Creating Multiple Messages Multi Buttons.
- Multi buttons select.
- Removing all multi buttons messages and the select message. .
- There is some Methods that will return either a DiscordID From either slash or normal commands.
- Same thing for GuildID.
- It does also contain FileUpload and SendMessages that both work with the slash and normal commands.
- Discord.net Preconditions.
- Markdown Utilities.
- String Utilities.
- More is to be added in the future.
Database Connection for mysql.
To properly use the features this addon provides you need to add the EmbedPagesService
or MultiButtonsService
to your service provider depending on which part you want.
var provider = new ServiceCollection()
.AddSingleton<EmbedPagesService>() // For embedding pages
.AddSingleton<MultiButtonsService>(); // For multi buttons
....
public EmbedPagesService EmbedPagesService { get; set; }
public MultiButtonsService MultiButtonsService { get; set; }
private readonly EmbedPagesService _embedPagesService;
private readonly MultiButtonsService _multiButtonsService;
public CTOR(EmbedPagesService embedPagesService, MultiButtonsService multiButtonsService) {
_embedPagesService = embedPagesService;
_multiButtonsService = multiButtonsService;
}
Inject the EmbedPagesService into your Module using DI instead. (Constructor / Public Property Injection).
[Command("Help")] // Remove this for slash commands
public async Task HelpAsync() {
List<EmbedBuilder> embedBuilders = new();
EmbedBuilder embedBuilder = new();
embedBuilder.WithTitle("Family System");
embedBuilder.WithDescription(
"This is the family system.");
embedBuilder.AddField("Planned Stuff:",
" - Family tree where it shows the families a bit better.\n " +
" - Remove Family Member.\n" +
" - Remove Family Connection.\n" +
" - Leave Family.\n\n" +
"Commands to help you:");
embedBuilder.AddField("!af or !addFamily", "Add a new family.");
embedBuilder.WithColorCode(ColorCodes.Aqua); // Use the colorCodes to find your specific color of what you want to use.
embedBuilders.Add(embedBuilder);
embedBuilder = new();
embedBuilder.WithTitle("Animal Searches");
embedBuilder.WithDescription("This is the animal picture system here is some commands to help you:");
embedBuilder.AddField("!cat", "Get a cat picture.");
embedBuilder.WithColorCode(ColorCodes.White); // Use the colorCodes to find your specific color of what you want to use.
embedBuilders.Add(embedBuilder);
await _embedPagesService.CreateEmbedPages(client, embedBuilders, context);
// await _embedPagesService.CreateEmbedPages(client, embedBuilders, command: command); //Or slashcommands
}
None of the EmbedPagesStyles has to be set what you see is their default values.
You can leave out all of them or some of them or change them at will.
[Command("Help")] // Remove this for slash commands
public async Task HelpAsync() {
EmbedPagesStyles style = new();
style.FirstLabel = "«";
style.BackLabel = "‹";
style.DeletionEmoji = "🗑";
style.ForwardLabel = "›";
style.LastLabel = "»";
style.DeletionMessage = "Embed page has been deleted";
style.BtnColor = ButtonStyle.Success;
style.DeletionBtnColor = ButtonStyle.Danger;
style.SkipBtnColor = ButtonStyle.Primary;
style.FastChangeBtns = false; // Do you want there to be a button that goes directly to either ends?
style.PageNumbers = true; //Do you want the embed to have page numbers like "Page: 1/4"? Depends on how many pages you have.
style.RemoveDeleteBtn = false; // Do you want to remove the Delete button (trash icon)?
style.ButtonDuration = 120000; // Change this to `0` if you want to disable the button disable timer. Or specify your own duration (in milliseconds).
await _embedPagesService.CreateEmbedPages(client, embedBuilders, context, style: style);
// await _embedPagesService.CreateEmbedPages(client, embedBuilders, command: command, style: style); //Or slashcommands
}
Inject the MultiButtonsService into your Module using DI instead. (Constructor / Public Property Injection).
You can do as i have done for making buttons that splits up people in your server by 25 pr button. Or just a long list of strings.
In order to get a list of users you have to activate the "Privileged Gateway Intents" those being "PRESENCE INTENT" and "SERVER MEMBERS INTENT" they can be set here by choosing your bot and going to the Bots tab. Remember if you your bot is in 100 or more servers then it needs to get verification and whitelisting from discord for the intents to work. Read more here.
public async Task CreateChooseChildButtons(SocketMessageComponent interaction) {
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
List<string> titles = new();
foreach (RestGuildUser user in users) titles.Add(user.Nickname ?? user.Username);
var builder = _multiButtonsService.CreateMultiButtons(titles);
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
None of the MultiButtonsStyles has to be set what you see is their default values.
You can leave out all of them or some of them or change them at will.
public async Task CreateChooseChildButtons(SocketMessageComponent interaction) {
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
List<string> titles = new();
foreach (RestGuildUser user in users) titles.Add(user.Nickname ?? user.Username);
MultiButtonsStyles multiButtonsStyles = new() {
CustomID = "multiButtons",
ButtonStyle = ButtonStyle.Success,
UpperCaseLetters = true,
OrderByTitle = true
};
var builder = _multiButtonsService.CreateMultiButtons(titles, multiButtonsStyles);
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
Inject the MultiButtonsService into your Module using DI instead. (Constructor / Public Property Injection).
You can do as i have done for making buttons that splits up people in your server by 25 pr button. Or just a long list of strings.
In order to get a list of users you have to activate the "Privileged Gateway Intents" those being "PRESENCE INTENT" and "SERVER MEMBERS INTENT" they can be set here by choosing your bot and going to the Bots tab. Remember if you your bot is in 100 or more servers then it needs to get verification and whitelisting from discord for the intents to work. Read more here.
public async Task CreateChooseChildButtons(SocketMessageComponent interaction) {
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
List<string> titles = new();
foreach (RestGuildUser user in users) titles.Add(user.Nickname ?? user.Username);
List<ComponentBuilder> builders = _multiButtonsService.CreateMultipleMultiButtons(titles);
foreach (ComponentBuilder builder in builders) {
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
}
After you use this you have to use the other part which is the selector: Link to Multi Buttons Select.
None of the MultiButtonsStyles has to be set what you see is their default values.
You can leave out all of them or some of them or change them at will.
public async Task CreateChooseChildButtons(SocketMessageComponent interaction) {
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
List<string> titles = new();
foreach (RestGuildUser user in users) titles.Add(user.Nickname ?? user.Username);
MultipleMultiButtonsStyles multipleMultiButtonsStyles = new() {
CustomID = "multiButtons",
ButtonStyle = ButtonStyle.Success,
UpperCaseLetters = true,
OrderByTitle = true,
DoNotAddLastButton = false,
MultiButtonsRows = MultiButtonsRows.Five
};
List<ComponentBuilder> builders = _multiButtonsService.CreateMultiButtons(titles, MultiButtonsRows.Five, multipleMultiButtonsStyles);
// List<ComponentBuilder> builders = _multiButtonsService.CreateMultipleMultiButtons(titles, styles: multipleMultiButtonsStyles);
foreach (ComponentBuilder builder in builders) {
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
}
Inject the MultiButtonsService into your Module using DI instead. (Constructor / Public Property Injection).
In order to get a list of users you have to activate the "Privileged Gateway Intents" those being "PRESENCE INTENT" and "SERVER MEMBERS INTENT" they can be set here by choosing your bot and going to the Bots tab. Remember if you your bot is in 100 or more servers then it needs to get verification and whitelisting from discord for the intents to work. Read more here.
Place this in side of your Button Handler and set the "multiButtons" to what your customId is.
private async Task ButtonHandler(SocketMessageComponent interaction) {
if (Regex.IsMatch(customId, "multiButtons[0-9]+")) await _buttonCommands.ChooseChildNameRange(interaction);
}
You need to give it the full list and it will figure out the rest. Again you can use it as i have with users or your own list.
public async Task ChooseChildNameRange(SocketMessageComponent interaction) {
List<MultiButton> multiButtons = new();
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
foreach (RestGuildUser user in users) {
MultiButton multiButton = new() {
Title = user.Nickname ?? user.Username,
Value = user.Id.ToString()
};
multiButtons.Add(multiButton);
}
var builder = await _multiButtonsService.CreateSelectForMultiButtonsAsync(interaction, multiButtons);
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
None of the MultiButtonsStyles has to be set what you see is their default values.
You can leave out all of them or some of them or change them at will.
public async Task ChooseChildNameRange(SocketMessageComponent interaction) {
List<MultiButton> multiButtons = new();
List<RestGuildUser> users = await _userService.GetSortedUserListAsync(((SocketGuildUser)interaction.User).Guild);
foreach (RestGuildUser user in users) {
MultiButton multiButton = new() {
Title = user.Nickname ?? user.Username,
Value = user.Id.ToString()
};
multiButtons.Add(multiButton);
}
SelectForMultiButtonsStyles selectForMultiButtonsStyles = new() {
CustomID = "chooseRange",
Placeholder = "Select Item",
RagedLettersOnEndOfPlaceholder = true,
OrderByTitle = true
};
var builder = _multiButtonsService.CreateSelectForMultiButtons(interaction, multiButtons, selectForMultiButtonsStyles);
await interaction.FollowupAsync("Choose Person", component: builder.Build());
}
public async Task OnSelectionChooseRange(SocketMessageComponent interaction) {
await _multiButtonsService.RemoveMultiButtonsAndSelectAsync(interaction);
}