'How to execute a command when clicking a button (discord.net)?
I want to execute my Task "test1", when the Button "Spieler moven" is clicked. How do i do that? Currently you write !test1 and than it executes. So a player clicks the button "Spieler moven" and the task "test1" gets executed.
[Command("spawner")]
public async Task Spawn()
{
var builder = new ComponentBuilder()
.WithButton("Spieler moven", "1", ButtonStyle.Success);
await ReplyAsync("Welche Option willst du ausführen?", components: builder.Build());
}
public async Task Test1()
{
var user = Context.User as SocketGuildUser;
var Queuelist = Context.Guild.GetVoiceChannel(936628853340778506).Users; //Checke ob jemand in der Warteschlange ist
bool Queue = false; //Standardmäßig Niemand in der Queue
foreach (var u in Queuelist)
{
Queue = true;
}
if (Queue == true)
{
var VoiceUsers = Context.Guild.GetVoiceChannel(936628853340778507).Users; // Checke ob Support 1 besetzt ist
bool sup1 = false;
foreach (var u in VoiceUsers)
{
bool supporter = u.Equals(Context.User); // Checke ob der Supporter selbst in Support 1 ist
if (supporter == false)
sup1 = true;
}
if (sup1 == false)
{
await user.ModifyAsync(x => { x.ChannelId = 936628853340778507; }); //Move zu Support 1
}
else
{
await user.ModifyAsync(x => { x.ChannelId = 936628853340778508; }); //Support 1 ist voll, move zu Support 2
}
} else
await ReplyAsync("" + Context.Message.Author.Mention + ", es befindet sich niemand bei Tränix :c");
}
Thanks beforehand
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
