You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClientBasics.md 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Client Basics Questions
  2. ## My client keeps returning 401 upon logging in!
  3. There are few possible reasons why this may occur.
  4. 1. You are not using the appropriate [TokenType].
  5. If you are using a bot account created from the Discord Developer
  6. portal, you should be using `TokenType.Bot`.
  7. 2. You are not using the correct login credentials.
  8. Please keep in mind that tokens start with `Mj*`.
  9. If it starts with any other characters, chances are, you might be
  10. using the *client secret*, which has nothing to do with the login
  11. token.
  12. [TokenType]: xref:Discord.TokenType
  13. ## How do I do X, Y, Z when my bot connects/logs on? Why do I get a `NullReferenceException` upon calling any client methods after connect?
  14. Your bot should not attempt to interact in any way with guilds/servers
  15. until the [Ready] event fires. When the bot connects, it first has to
  16. download guild information from Discord in order for you to get
  17. access to any server information; the client is not ready at this
  18. point.
  19. Technically, the [GuildAvailable] event fires once the data for a
  20. particular guild has downloaded; however, it's best to wait for all
  21. guilds to be downloaded. Once all downloads are complete, the [Ready]
  22. event is triggered, then you can proceed to do whatever you like.
  23. [Ready]: xref:Discord.WebSocket.DiscordSocketClient#Discord_WebSocket_DiscordSocketClient_Ready
  24. [GuildAvailable]: xref:Discord.WebSocket.BaseSocketClient#Discord_WebSocket_BaseSocketClient_GuildAvailable
  25. ## How do I get a message's previous content when that message is edited?
  26. If you need to do anything with messages (e.g. checking Reactions,
  27. checking the content of edited/deleted messages), you must set the
  28. [MessageCacheSize] in your [DiscordSocketConfig] settings in order to
  29. use the cached message entity. Read more about it [here](../guides/concepts/events.md#cacheable).
  30. 1. Message Cache must be enabled.
  31. 2. Hook the MessageUpdated event. This event provides a *before* and
  32. *after* object.
  33. 3. Only messages received *after* the bot comes online will be
  34. available in the cache.
  35. [MessageCacheSize]: xref:Discord.WebSocket.DiscordSocketConfig#Discord_WebSocket_DiscordSocketConfig_MessageCacheSize
  36. [DiscordSocketConfig]: xref:Discord.WebSocket.DiscordSocketConfig
  37. [MessageUpdated]: xref:Discord.WebSocket.BaseSocketClient#Discord_WebSocket_BaseSocketClient_MessageUpdated