discord token is now in token file
This commit is contained in:
parent
f4cf2620d9
commit
2178ff54b6
4 changed files with 12 additions and 64 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -19,6 +19,10 @@ mono_crash.*
|
||||||
# Sqlite Database
|
# Sqlite Database
|
||||||
Database/
|
Database/
|
||||||
|
|
||||||
|
# Discord Tokens
|
||||||
|
DiscordBot/token.txt
|
||||||
|
DiscordBot/debugtoken.txt
|
||||||
|
|
||||||
# Build results
|
# Build results
|
||||||
[Dd]ebug/
|
[Dd]ebug/
|
||||||
[Dd]ebugPublic/
|
[Dd]ebugPublic/
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace DiscordBot.Controllers
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class WeatherForecastController : ControllerBase
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet(Name = "GetWeatherForecast")]
|
|
||||||
public IEnumerable<WeatherForecast> Get()
|
|
||||||
{
|
|
||||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(index),
|
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
||||||
})
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -79,16 +79,11 @@ namespace DiscordBot
|
||||||
_client.Log += Log;
|
_client.Log += Log;
|
||||||
_client.Ready += Client_Ready;
|
_client.Ready += Client_Ready;
|
||||||
|
|
||||||
// You can assign your bot token to a string, and pass that in to connect.
|
#if DEBUG
|
||||||
// This is, however, insecure, particularly if you plan to have your code hosted in a public repository.
|
var token = File.ReadAllText("debugtoken.txt");
|
||||||
var token = "MTAxODE3MDczMDU0Mzg1Nzc3NA.GA2Qzu.__kLICXm-8VLTQD6KzL-uGaPx60Q6fn8K6lE3A";
|
#else
|
||||||
//var token = "Njc2NzQ4NjM2NjI5MTA2NzE4.Xtu2Ww._2oF7lQtxLLOUhfAIMxocN52dYo";
|
var token = File.ReadAllText("token.txt");
|
||||||
|
#endif
|
||||||
// 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;
|
|
||||||
|
|
||||||
await _client.LoginAsync(TokenType.Bot, token);
|
await _client.LoginAsync(TokenType.Bot, token);
|
||||||
await _client.StartAsync();
|
await _client.StartAsync();
|
||||||
|
|
||||||
|
@ -109,10 +104,8 @@ namespace DiscordBot
|
||||||
|
|
||||||
public async Task Client_Ready()
|
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);
|
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()
|
var guildCommand = new SlashCommandBuilder()
|
||||||
.WithName(Constants.SlashCommands.RAID)
|
.WithName(Constants.SlashCommands.RAID)
|
||||||
.WithDescription("Raid commands")
|
.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.
|
// 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.
|
// 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.Errors, Formatting.Indented);
|
||||||
//var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented);
|
Console.WriteLine(json);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
namespace DiscordBot
|
|
||||||
{
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue