1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| using Discord;
using Discord.WebSocket;
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Net;
using Newtonsoft.Json;
namespace Overated
{
class Program
{
private DiscordSocketClient _Bot;
public string keyname, realm, armorstack, advname, comment;
public int price, keylevel, nbrkey;
public static void Main(string[] args) => new Program().RunBot().GetAwaiter().GetResult();
public async Task RunBot()
{
_Bot = new DiscordSocketClient();
_Bot.SlashCommandExecuted += SlashCommandHandler;
var token = Environment.GetEnvironmentVariable("Token", EnvironmentVariableTarget.User);
await _Bot.LoginAsync(TokenType.Bot, token);
await _Bot.StartAsync();
_Bot.Ready += Client_Ready;
_Bot.Ready += () =>
{
Console.WriteLine("Rani hnaya");
return Task.CompletedTask;
};
_Bot.Log += Log;
await Task.Delay(-1);
}
private async Task SlashCommandHandler(SocketSlashCommand command)
{
var value = command.Data.Options.First().Options.First().Options?.FirstOrDefault().Value;
this.keyname = (string)value;
await command.RespondAsync($"Vous venez d'exeucter {command.Data.Name} la valeur est : " + keyname);
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
public async Task Client_Ready()
{
var guild = _Bot.GetGuild(8);
var globalCommand = new SlashCommandBuilder()
.WithName("create-event-boost")
.WithDescription("créer un event boost")
.AddOption(new SlashCommandOptionBuilder()
.WithName("field-a")
.WithDescription("Gets or sets the field A")
.WithType(ApplicationCommandOptionType.SubCommandGroup)
.AddOption(new SlashCommandOptionBuilder()
.WithName("set")
.WithDescription("Sets the field A")
.WithType(ApplicationCommandOptionType.SubCommand)
.AddOption("keyname", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true)
.AddOption("realm", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true)
.AddOption("armorstack", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true)
.AddOption("advname", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true)
.AddOption("comment", ApplicationCommandOptionType.String, "the value to set the field", isRequired: true)
.AddOption("price", ApplicationCommandOptionType.Integer, "the value to set the field", isRequired: true)
.AddOption("keylevel", ApplicationCommandOptionType.Integer, "the value to set the field", isRequired: true)
.AddOption("nbrkey", ApplicationCommandOptionType.Integer, "the value to set the field", isRequired: true)
));
try
{
await _Bot.CreateGlobalApplicationCommandAsync(globalCommand.Build());
}
catch (ApplicationCommandException exception)
{
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
Console.WriteLine(json);
}
}
}
} |
Partager