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
what's Events.Logging.Log ? π€
it another file to for logging mssages etc
but overall is it correct?
yes it looks correct
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
next time juste put it directly
okay
do you know what the cause of this error ?
@xtreit do you have any idea?
nop it's weird
try asking in discord.NET server
i searched there no server for discord.net
maybe in discord developers
oh ok
thanks
Imagine discord bot library not having a discord server