Parameters
Component interaction parameters allow you to pass data to components during their creation. For example, you can pass a user ID to ban or the content of a message to send. By default, parameters are separated by a colon (:), but this behavior can be customized by setting ParameterSeparator in the configuration. This guide assumes the default separator is used.
Type Readers
NetCord uses type readers to convert parameters to their respective types. The following table lists the default type readers and the types they read.
Expand to see the full list of built-in type readers.
Remainder
The last parameter is always considered a remainder. This means that it can contain any number of colons. This is useful when you want to pass a string that may contain colons.
For example, using a custom ID like publish:testing 1 2 3 would send an embed with the content testing 1 2 3.
[ComponentInteraction("publish")]
public static InteractionMessageProperties Publish(string content)
{
return new InteractionMessageProperties()
.AddEmbeds(new EmbedProperties().WithTitle("Publication")
.WithDescription(content)
.WithColor(new Color(0x7777FF)));
}
Variable Number of Parameters
You can use the params keyword to accept a variable number of parameters.
For example, a custom ID like delete:931274046312701962:963913427661766717 would delete messages with the IDs 931274046312701962 and 963913427661766717.
[ComponentInteraction("delete")]
public async Task<string> DeleteAsync(params ulong[] messageIds)
{
await Context.Channel.DeleteMessagesAsync(messageIds);
return "The messages have been deleted successfully.";
}
Optional Parameters
To mark parameters as optional, assign them a default value.
For example, the following custom IDs can be used:
unban:735048387178659854:(note the trailing:to indicate the omission of thereasonparameter) to unban the user without specifying a reason.unban:735048387178659854:proof of innocenceto unban the user and provide a reason.
[ComponentInteraction("unban")]
public async Task<string> UnbanAsync(ulong userId, string reason = "No reason provided.")
{
await Context.Guild!.UnbanUserAsync(userId, new RestRequestProperties().WithAuditLogReason(reason));
return $"The user has been unbanned successfully.";
}
In another example, with two optional parameters, you can use these custom IDs:
bug report:troll::(note the two consecutive colons::at the end to indicate the omission of bothbodyandcategoryparameters) to create a bug report titledtrollwithout a body or category.bug report:Channel Disappeared:I can no longer find the general channel:(note the trailing colon:to indicate the omission of thecategoryparameter) to create a bug report with a title and body, but no category.bug report:Bot Bug::Bot(note the two consecutive colons::in the middle to indicate the omission of thebodyparameter) to create a bug report with a title and category but no body.bug report:Wrong Channel Permissions:I am able to send messages in the announcements channel:Permissionsto create a bug report with all parameters specified.
[ComponentInteraction("bug report")]
public static InteractionMessageProperties BugReport(string title, string body = "No body provided.", string category = "None")
{
return new InteractionMessageProperties()
.AddEmbeds(new EmbedProperties()
.WithColor(new(0xFF0000))
.WithTitle(title)
.WithDescription(body)
.WithFooter(new EmbedFooterProperties().WithText($"Category: {category}")));
}