Immortal
Immortal
CC#
Created by Immortal on 5/22/2024 in #help
Is this the correct way to replace to replace a discord bot background service logger with Serilog?
Here's my Bot class in case you need to see how I'm using it: (Sorry for ping) https://paste.mod.gg/oskmoomckcag/0
6 replies
CC#
Created by Immortal on 5/22/2024 in #help
Is this the correct way to replace to replace a discord bot background service logger with Serilog?
6 replies
CC#
Created by Immortal on 5/22/2024 in #help
Is this the correct way to replace to replace a discord bot background service logger with Serilog?
No description
6 replies
CC#
Created by Immortal on 5/20/2024 in #help
✅ Difference between CreateApplicationBuilder and CreateDefaultBuilder?
Thanks for the explanation
7 replies
CC#
Created by Immortal on 5/20/2024 in #help
✅ Difference between CreateApplicationBuilder and CreateDefaultBuilder?
Guessing that's why worker template uses CreateApplicationBuilder() now? since from what I've seen, in the past worker template used to use CreateDefaultBuilder()
7 replies
CC#
Created by Immortal on 5/20/2024 in #help
✅ Difference between CreateApplicationBuilder and CreateDefaultBuilder?
I see, so is there any reason to use CreateDefaultBuilder() over CreateApplicationBuilder()?
7 replies
CC#
Created by Immortal on 5/20/2024 in #help
✅ Difference between CreateApplicationBuilder and CreateDefaultBuilder?
Like don't these code blocks do the same thing?
var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHostedService<Bot>();

builder.Services.AddSingleton<DiscordClient>((serviceProvider) =>
{
var config = builder.Configuration;

var discordClient = new DiscordClient(new DiscordConfiguration
{
Token = config["DiscordBotToken"],
TokenType = TokenType.Bot,
AutoReconnect = true,
Intents = DiscordIntents.All
});

var slash = discordClient.UseSlashCommands(new SlashCommandsConfiguration
{
Services = serviceProvider
});

SlashRegistry.RegisterCommands(slash);

return discordClient;
});
var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHostedService<Bot>();

builder.Services.AddSingleton<DiscordClient>((serviceProvider) =>
{
var config = builder.Configuration;

var discordClient = new DiscordClient(new DiscordConfiguration
{
Token = config["DiscordBotToken"],
TokenType = TokenType.Bot,
AutoReconnect = true,
Intents = DiscordIntents.All
});

var slash = discordClient.UseSlashCommands(new SlashCommandsConfiguration
{
Services = serviceProvider
});

SlashRegistry.RegisterCommands(slash);

return discordClient;
});
var builder = Host.CreateDefaultBuilder(args).ConfigureServices(services =>
{
services.AddHostedService<Bot>();

services.AddSingleton<DiscordClient>((serviceProvider) =>
{
var config = serviceProvider.GetRequiredService<IConfiguration>();

var discordClient = new DiscordClient(new DiscordConfiguration
{
Token = config["DiscordBotToken"],
TokenType = TokenType.Bot,
AutoReconnect = true,
Intents = DiscordIntents.All
});

var slash = discordClient.UseSlashCommands(new SlashCommandsConfiguration
{
Services = serviceProvider
});

SlashRegistry.RegisterCommands(slash);

return discordClient;
});
var builder = Host.CreateDefaultBuilder(args).ConfigureServices(services =>
{
services.AddHostedService<Bot>();

services.AddSingleton<DiscordClient>((serviceProvider) =>
{
var config = serviceProvider.GetRequiredService<IConfiguration>();

var discordClient = new DiscordClient(new DiscordConfiguration
{
Token = config["DiscordBotToken"],
TokenType = TokenType.Bot,
AutoReconnect = true,
Intents = DiscordIntents.All
});

var slash = discordClient.UseSlashCommands(new SlashCommandsConfiguration
{
Services = serviceProvider
});

SlashRegistry.RegisterCommands(slash);

return discordClient;
});
7 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
public class Bot
{
public required Config Config { get; set; }
public required DiscordClient Client { get; set; }
public required SlashCommandsExtension Slash { get; set; }
}
public class Bot
{
public required Config Config { get; set; }
public required DiscordClient Client { get; set; }
public required SlashCommandsExtension Slash { get; set; }
}
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Can't do that with private set since can't have access level be less visible than the class it's in so I'd have to remove private set from the properties
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
:catlove:
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Thank you so much c:
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
I'll look into it :>
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
also should I be using a json or environment variable for my token or does it not matter really?
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Thanks for your help! :catlove:
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
I think I got it
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Ahhh I see
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Thank you, it makes sense. So I made a contructor to call the InitializeConfig method but that doesn't get rid of the warning. Can I not do that? bit off topic but should I be using a json to store the token? I also heard that storing the token as an environment variable is an option https://paste.mod.gg/mogaxsqbjomh/0
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
Yeah I was temporarily using ? to make it nullable but a Config for a bot should really be null I think so I removed it to learn better practice
45 replies
CC#
Created by Immortal on 5/2/2024 in #help
✅ Best practices regarding non-nullable property warnings?
So like which approach should I go with to correct these warnings?
45 replies