In the following section, you will find commonly asked questions and
answers about common issues that you may face when utilizing the
various clients offered by the library.
[!WARNING]
Userbot/selfbot (logging in with a user token) is no
longer supported with this library starting from 2.0, as
logging in under a user account may result in account termination.For more information, see issue 827 & 958, as well as the official
Discord API Terms of Service.
There are few possible reasons why this may occur.
TokenType.Bot
.NullReferenceException
upon calling any client methods after connect?Your bot should not attempt to interact in any way with
guilds/servers until the Ready event fires. When the bot
connects, it first has to download guild information from
Discord for you to get access to any server
information; the client is not ready at this point.
Technically, the GuildAvailable event fires once the data for a
particular guild has downloaded; however, it is best to wait for all
guilds to be downloaded. Once all downloads are complete, the Ready
event is triggered, then you can proceed to do whatever you like.
If you need to do anything with messages (e.g., checking Reactions,
checking the content of edited/deleted messages), you must set the
MessageCacheSize in your DiscordSocketConfig settings in order to
use the cached message entity. Read more about it here.
DiscordSocketClient
?As your bot grows in popularity, it is recommended that you should section your bot off into separate processes.
The DiscordShardedClient is essentially a class that allows you to easily create and manage multiple DiscordSocketClient
instances, with each one serving a different amount of guilds.
There are very few differences from the DiscordSocketClient class, and it is very straightforward
to modify your existing code to use a DiscordShardedClient when necessary.
Shards
property.If you do not wish to use the DiscordShardedClient and instead reuse the same DiscordSocketClient code and manually shard them,
you can do so by specifying the ShardId for the DiscordSocketConfig and pass that to the DiscordSocketClient's constructor.