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.

client-basics.md 2.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ---
  2. uid: FAQ.Basics.ClientBasics
  3. title: Basic Questions about Client
  4. ---
  5. # Client Basics Questions
  6. ## My client keeps returning 401 upon logging in!
  7. > [!WARNING]
  8. > Userbot/selfbot (logging in with a user token) is not
  9. > officially supported with this library.
  10. >
  11. > Logging in under a user account may result in account
  12. > termination!
  13. There are few possible reasons why this may occur.
  14. 1. You are not using the appropriate [TokenType]. If you are using a
  15. bot account created from the Discord Developer portal, you should
  16. be using `TokenType.Bot`.
  17. 2. You are not using the correct login credentials. Please keep in
  18. mind that tokens is different from a *client secret*.
  19. [TokenType]: xref:Discord.TokenType
  20. ## 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?
  21. Your bot should **not** attempt to interact in any way with
  22. guilds/servers until the [Ready] event fires. When the bot
  23. connects, it first has to download guild information from
  24. Discord in order for you to get access to any server
  25. information; the client is not ready at this point.
  26. Technically, the [GuildAvailable] event fires once the data for a
  27. particular guild has downloaded; however, it's best to wait for all
  28. guilds to be downloaded. Once all downloads are complete, the [Ready]
  29. event is triggered, then you can proceed to do whatever you like.
  30. [Ready]: xref:Discord.WebSocket.DiscordSocketClient.Ready
  31. [GuildAvailable]: xref:Discord.WebSocket.BaseSocketClient.GuildAvailable
  32. ## How do I get a message's previous content when that message is edited?
  33. If you need to do anything with messages (e.g. checking Reactions,
  34. checking the content of edited/deleted messages), you must set the
  35. [MessageCacheSize] in your [DiscordSocketConfig] settings in order to
  36. use the cached message entity. Read more about it [here](xref:Guides.Concepts.Events#cacheable).
  37. 1. Message Cache must be enabled.
  38. 2. Hook the MessageUpdated event. This event provides a *before* and
  39. *after* object.
  40. 3. Only messages received *after* the bot comes online will be
  41. available in the cache.
  42. [MessageCacheSize]: xref:Discord.WebSocket.DiscordSocketConfig.MessageCacheSize
  43. [DiscordSocketConfig]: xref:Discord.WebSocket.DiscordSocketConfig
  44. [MessageUpdated]: xref:Discord.WebSocket.BaseSocketClient.MessageUpdated