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.6 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 no
  9. > longer supported with this library starting from 2.0, as
  10. > logging in under a user account may result in account termination.
  11. >
  12. > For more information, see issue [827] & [958], as well as the official
  13. > [Discord API Terms of Service].
  14. There are few possible reasons why this may occur.
  15. 1. You are not using the appropriate [TokenType]. If you are using a
  16. bot account created from the Discord Developer portal, you should
  17. be using `TokenType.Bot`.
  18. 2. You are not using the correct login credentials. Please keep in
  19. mind that tokens is **different** from a *client secret*.
  20. [TokenType]: xref:Discord.TokenType
  21. [827]: https://github.com/RogueException/Discord.Net/issues/827
  22. [958]: https://github.com/RogueException/Discord.Net/issues/958
  23. [Discord API Terms of Service]: https://discordapp.com/developers/docs/legal
  24. ## 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?
  25. Your bot should **not** attempt to interact in any way with
  26. guilds/servers until the [Ready] event fires. When the bot
  27. connects, it first has to download guild information from
  28. Discord in order for you to get access to any server
  29. information; the client is not ready at this point.
  30. Technically, the [GuildAvailable] event fires once the data for a
  31. particular guild has downloaded; however, it's best to wait for all
  32. guilds to be downloaded. Once all downloads are complete, the [Ready]
  33. event is triggered, then you can proceed to do whatever you like.
  34. [Ready]: xref:Discord.WebSocket.DiscordSocketClient.Ready
  35. [GuildAvailable]: xref:Discord.WebSocket.BaseSocketClient.GuildAvailable
  36. ## How do I get a message's previous content when that message is edited?
  37. If you need to do anything with messages (e.g. checking Reactions,
  38. checking the content of edited/deleted messages), you must set the
  39. [MessageCacheSize] in your [DiscordSocketConfig] settings in order to
  40. use the cached message entity. Read more about it [here](xref:Guides.Concepts.Events#cacheable).
  41. 1. Message Cache must be enabled.
  42. 2. Hook the MessageUpdated event. This event provides a *before* and
  43. *after* object.
  44. 3. Only messages received *after* the bot comes online will be
  45. available in the cache.
  46. [MessageCacheSize]: xref:Discord.WebSocket.DiscordSocketConfig.MessageCacheSize
  47. [DiscordSocketConfig]: xref:Discord.WebSocket.DiscordSocketConfig
  48. [MessageUpdated]: xref:Discord.WebSocket.BaseSocketClient.MessageUpdated