There are few possible reasons why this may occur.
TokenType
. If you are using a bot account created from the Discord Developer portal, you should be using TokenType.Bot
.Mj*
. If it starts with any other characters, chances are, you are using the client secret, which has nothing to do with the login token.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 in order 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's 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.
MessageUpdated
event. This event provides a before and after object.