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

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