Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending messages with buttons using Discord.net

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 :>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading