#bot wont send messages
1 messages · Page 1 of 1 (latest)
I would btw generally recommend to use Slash Commands. Was there a reason why you chose to do it with text based commands?
The starting setup is a very complicated thing in itself and I am not 100% sure how to generally trouble shoot it but I can share what's been working for me so far if you want
Start of my Program.cs looks like this:
class Program
{
private DiscordSocketClient _client;
private readonly IServiceProvider _serviceProvider;
private InteractionService _services;
private IConnectionMultiplexer _redis;
private bool isReady = false;
public Program()
{
_serviceProvider = CreateProvider();
}
public static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
The IConnectionMultiplexer is not needed, neither is the bool isReady
CreateProvider method coming:
private static IServiceProvider CreateProvider()
{
var config = new DiscordSocketConfig()
{
MessageCacheSize = 100,
GatewayIntents = GatewayIntents.All,
AlwaysDownloadUsers = true,
LogLevel = LogSeverity.Info
};
var serviceConfig = new InteractionServiceConfig()
{
EnableAutocompleteHandlers = false
};
var collection = new ServiceCollection()
.AddSingleton(config)
.AddSingleton<DiscordSocketClient>()
.AddSingleton(serviceConfig)
.AddSingleton<InteractionService>();
return collection.BuildServiceProvider();
}
There you also got the GatewayIntents
And in the MainAsync Method now:
public async Task MainAsync()
{
_client = _serviceProvider.GetRequiredService<DiscordSocketClient>();
_services = _serviceProvider.GetRequiredService<InteractionService>();
//_redis = _serviceProvider.GetRequiredService<IConnectionMultiplexer>();
_client.Log += Log;
//await RegisterCommandsAsync();
var token = Environment.GetEnvironmentVariable("...");
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
// _client.Ready += Client_Ready;
// AddEventHandlers();
await Task.Delay(-1);
}
I commented those out that you don't need or have to replace with the command equivalent
Sure, let me know
Better delete the screenshot again
Your token
Anyhow
That's unlikely as with bruteforce they will need eons to crack a code that long 😄
Can you just send the error message again?
Ty
Click on show callstack please
You did put the Program constructor with the CreateProvider method there right?
Nah, you should the attributes
Just add all that I sent you :D
Maybe put your token in a file and read it
Then it's better for sharing
Yeah
You're still missing the first two code blocks I sent
And put the method CreateProvider() at the end of the class
It doesnt show any changes
Only on my phone rn
If you're still up in 4 to 5 hours I could get back to my pc
You can create a git repository and push stuff there
Only other way I can think of rn
You're still missing this
Won't be able to talk though, but watching and listening will work 👍
That's only the method but it doesnt call that method anywhere
No
You know what a constructor is?
It sets certain class variables or executes methods upon class creation
Usually it's:
attributes (or variables)
constructor
main method
other methods
Just put that right at the top of the class and you're good
Hover over it and tell me what it says
Add those two lines under the DiscordSocketClient before the main method:
private readonly IServiceProvider _serviceProvider;
private InteractionService _services;
@hardy fern
Why did you remove the first lines of the main again?
They were important too 😂
I gotta go now I'll have to look at it later
hey @hardy fern I'm on my pc now
hey, did you get it working?
you can now?