C
C#6mo ago
.Dja8x~

Discord.net

is this code correct ?
using System;
using Discord;
using Discord.Webhook;
using Discord.WebSocket;
using Discord.Commands;
using Events;
using System.Reflection;


public class Program {

public DiscordSocketClient? Client;
private DiscordSocketConfig GetSerpentConfig() {

return new DiscordSocketConfig() {GatewayIntents = GatewayIntents.All};
}
public async Task MainAsync() {
string Token = "MY_ACTUAL_BOT_TOKEN";

Client = new DiscordSocketClient(GetSerpentConfig());

Client.Log += Events.Logging.Log;
Client.Ready += Events.Logging.Ready;
Client.MessageReceived += Events.Messaging.MessageReceive;
Client.InteractionCreated += Events.Logging.HandleInteractions;

await Client.LoginAsync(TokenType.Bot,Token);

await Client.StartAsync();

await Task.Delay(-1);

}
public static Task Main() => new Program().MainAsync();



};
using System;
using Discord;
using Discord.Webhook;
using Discord.WebSocket;
using Discord.Commands;
using Events;
using System.Reflection;


public class Program {

public DiscordSocketClient? Client;
private DiscordSocketConfig GetSerpentConfig() {

return new DiscordSocketConfig() {GatewayIntents = GatewayIntents.All};
}
public async Task MainAsync() {
string Token = "MY_ACTUAL_BOT_TOKEN";

Client = new DiscordSocketClient(GetSerpentConfig());

Client.Log += Events.Logging.Log;
Client.Ready += Events.Logging.Ready;
Client.MessageReceived += Events.Messaging.MessageReceive;
Client.InteractionCreated += Events.Logging.HandleInteractions;

await Client.LoginAsync(TokenType.Bot,Token);

await Client.StartAsync();

await Task.Delay(-1);

}
public static Task Main() => new Program().MainAsync();



};
11 Replies
x0rld
x0rld6mo ago
what's Events.Logging.Log ? 🤔
.Dja8x~
.Dja8x~6mo ago
it another file to for logging mssages etc but overall is it correct?
x0rld
x0rld6mo ago
yes it looks correct
.Dja8x~
.Dja8x~6mo ago
it throws this error :
Log : 12:03:50 Discord Discord.Net v3.13.0 (API v10)
Log : 12:03:50 Gateway Connecting
Log : 12:03:53 Gateway Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Discord.API.Rest.GetBotGatewayResponse. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'url', line 1, position 7.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader, JsonObjectContract, JsonProperty , JsonProperty , String , Boolean& )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader , Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader , Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader , Type, Boolean)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader , Type)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader , Type)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader )
at Discord.API.DiscordRestApiClient.DeserializeJson[T](Stream)
at Discord.API.DiscordRestApiClient.SendAsync[TResponse](String, String, BucketId , ClientBucketType , RequestOptions )
at Discord.API.DiscordSocketApiClient.ConnectInternalAsync()
at Discord.API.DiscordSocketApiClient.ConnectInternalAsync()
at Discord.API.DiscordSocketApiClient.ConnectAsync()
at Discord.WebSocket.DiscordSocketClient.OnConnectingAsync()
at Discord.ConnectionManager.ConnectAsync(CancellationTokenSource)
at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
Log : 12:03:53 Gateway Disconnecting
Log : 12:03:53 Gateway Disconnected
Log : 12:03:50 Discord Discord.Net v3.13.0 (API v10)
Log : 12:03:50 Gateway Connecting
Log : 12:03:53 Gateway Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Discord.API.Rest.GetBotGatewayResponse. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'url', line 1, position 7.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader, JsonObjectContract, JsonProperty , JsonProperty , String , Boolean& )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader , Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader , Type, JsonContract, JsonProperty, JsonContainerContract, JsonProperty, Object)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader , Type, Boolean)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader , Type)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader , Type)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader )
at Discord.API.DiscordRestApiClient.DeserializeJson[T](Stream)
at Discord.API.DiscordRestApiClient.SendAsync[TResponse](String, String, BucketId , ClientBucketType , RequestOptions )
at Discord.API.DiscordSocketApiClient.ConnectInternalAsync()
at Discord.API.DiscordSocketApiClient.ConnectInternalAsync()
at Discord.API.DiscordSocketApiClient.ConnectAsync()
at Discord.WebSocket.DiscordSocketClient.OnConnectingAsync()
at Discord.ConnectionManager.ConnectAsync(CancellationTokenSource)
at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
Log : 12:03:53 Gateway Disconnecting
Log : 12:03:53 Gateway Disconnected
x0rld
x0rld6mo ago
next time juste put it directly
.Dja8x~
.Dja8x~6mo ago
okay do you know what the cause of this error ? @xtreit do you have any idea?
x0rld
x0rld6mo ago
nop it's weird try asking in discord.NET server
.Dja8x~
.Dja8x~6mo ago
i searched there no server for discord.net maybe in discord developers
.Dja8x~
.Dja8x~6mo ago
oh ok thanks
mindhardt
mindhardt6mo ago
Imagine discord bot library not having a discord server