C
C#β€’11mo 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 πŸ‘» πŸŽƒ
what's Events.Logging.Log ? πŸ€”
.Dja8x~
.Dja8x~OPβ€’11mo ago
it another file to for logging mssages etc but overall is it correct?
x0rld πŸ‘» πŸŽƒ
yes it looks correct
.Dja8x~
.Dja8x~OPβ€’11mo 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 πŸ‘» πŸŽƒ
next time juste put it directly
.Dja8x~
.Dja8x~OPβ€’11mo ago
okay do you know what the cause of this error ? @xtreit do you have any idea?
x0rld πŸ‘» πŸŽƒ
nop it's weird try asking in discord.NET server
.Dja8x~
.Dja8x~OPβ€’11mo ago
i searched there no server for discord.net maybe in discord developers
.Dja8x~
.Dja8x~OPβ€’11mo ago
oh ok thanks
mindhardt
mindhardtβ€’11mo ago
Imagine discord bot library not having a discord server
Want results from more Discord servers?
Add your server