discord token is now in token file

This commit is contained in:
Sarah Faey 2022-11-22 22:38:32 +01:00
parent f4cf2620d9
commit 2178ff54b6
4 changed files with 12 additions and 64 deletions

View file

@ -79,16 +79,11 @@ namespace DiscordBot
_client.Log += Log;
_client.Ready += Client_Ready;
// You can assign your bot token to a string, and pass that in to connect.
// This is, however, insecure, particularly if you plan to have your code hosted in a public repository.
var token = "MTAxODE3MDczMDU0Mzg1Nzc3NA.GA2Qzu.__kLICXm-8VLTQD6KzL-uGaPx60Q6fn8K6lE3A";
//var token = "Njc2NzQ4NjM2NjI5MTA2NzE4.Xtu2Ww._2oF7lQtxLLOUhfAIMxocN52dYo";
// Some alternative options would be to keep your token in an Environment Variable or a standalone file.
// var token = Environment.GetEnvironmentVariable("NameOfYourEnvironmentVariable");
// var token = File.ReadAllText("token.txt");
// var token = JsonConvert.DeserializeObject<AConfigurationClass>(File.ReadAllText("config.json")).Token;
#if DEBUG
var token = File.ReadAllText("debugtoken.txt");
#else
var token = File.ReadAllText("token.txt");
#endif
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
@ -109,10 +104,8 @@ namespace DiscordBot
public async Task Client_Ready()
{
// Let's build a guild command! We're going to need a guild so lets just put that in a variable.
var guild = _client.GetGuild(666953424734257182);
// Next, lets create our slash command builder. This is like the embed builder but for slash commands.
var guildCommand = new SlashCommandBuilder()
.WithName(Constants.SlashCommands.RAID)
.WithDescription("Raid commands")
@ -166,13 +159,10 @@ namespace DiscordBot
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (ApplicationCommandException exception)
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
//var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
//Console.WriteLine(json);
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
Console.WriteLine(json);
}
}