I have just spent the better part of an hour searching for ways to send a button with a message using Discord.Net. In one of their recent merges with Discord.Net-Labs, they said they added a bunch of things, including buttons. However, checking both of their documentation, I couldn't find any way to add a button to a message. I would appreciate an example and/or link to an example of attaching buttons. Thanks :>
CodePudding user response:
It looks like there is documentation here
Example from the above link:
[Command("spawner")]
public async Task Spawn()
{
var builder = new ComponentBuilder()
.WithButton("label", "custom-id");
await ReplyAsync("Here is a button!", components: builder.Build());
}
To receive an event when someone interacts with a button, you can subscribe to DiscordSocketClient.ButtonExecuted
. The handler for this event takes a SocketMessageComponent
object as an argument.