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.

basic-operations.md 4.1 kB

Squashed commit of the following: commit dece19d89505342e5f8c51317b54be8ce69336c9 Merge: fdaa689a e764dafe Author: Still Hsu <341464@gmail.com> Date: Mon May 21 11:47:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit e764dafe083bf5db62091ac1f6b3d438eee38882 Author: Quahu <quahuu@gmail.com> Date: Sun May 13 15:34:40 2018 +0200 Add ViewChannel to Voice channel permissions (#1059) Previously, Voice channels did not have ViewChannel in their "all" permissions commit 32fc2df21b1840fd913ccce80c0686e8e853b43d Author: Alex Gravely <tcbskater@hotmail.com> Date: Sat May 12 20:47:44 2018 -0400 Remove unused field in EmbedFieldBuilder. (#1018) commit 39dffe858584d0e9eed750bff6426e9562db4262 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Sun May 13 01:46:07 2018 +0100 Audit Logs implementation (#1055) * Copy audit logs impl from old branch and clean up I suck at using git, so I'm gonna use brute force. * Remove unnecessary TODOs Category channels do not provide any new information, and the other I forgot to remove beforehand * Add invite update data, clean up after feedback * Remove TODOs, add WebhookType enum for future use WebhookType is a future-use type, as currently audit logs are the only thing which may return it. commit fdaa689ae8be8e9d2ff5190b6cfed5af244b805b Author: Still Hsu <341464@gmail.com> Date: Wed May 9 06:04:59 2018 +0800 Add explanation for RunMode commit ea82c2537e64d4b75f85d9369e90cb55cfcadcc7 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 16:30:48 2018 +0800 Initial proofread of the articles commit 124f1a267c663fbbb0f2dc23367dd910ae3ba4cc Merge: 25557218 97c89310 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 05:02:01 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit 97c893107b51de24a38ea03c2f8260030c8fc7f5 Author: Still Hsu <341464@gmail.com> Date: Mon May 7 06:22:49 2018 +0800 Implement GetBanAsync (#1056) commit 25557218dbc9390dbeac108afc153776f52dc26f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 16:11:19 2018 +0800 Add details to SpotifyGame commit c7b236ddf5d7324dd8c1513ccd528a7a45d0031f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:58:23 2018 +0800 Add more IGuild docs commit 1bb06cc37b7c2312b0ab111da63026a01da01e42 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:40:31 2018 +0800 Replace all langword placements with code block commit ac47d84ea74c81e136434dcc33967fe4cd95c1e6 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:22:17 2018 +0800 Replace langword null to code block null instead - Because DocFX sucks at rendering langword commit 0b15bbc54d15c036f770bab818712956c527b4ee Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:20:34 2018 +0800 Add XML docs commit 65d4e4360eb88e3bc5cc8f0da6135e5ee997af6c Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:57:53 2018 +0800 Add BaseSocketClient docs commit 8f64c045999c1bb0440bdc818f082e7459756b36 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:37:55 2018 +0800 Replace note block commit d8bb9e7aaa1e908ceb9227285c0cebec9add5280 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:31:50 2018 +0800 Add warning for bulk-delete endpoint commit adae5ffc9e42343f170d6c869644637587330b59 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:07:28 2018 +0800 Fix missing Username prop commit 3e591972cafdffb6692a1b94cf9a63251188df8b Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:01:34 2018 +0800 Add properties examples to overwrite commit 0ad66f6765addf6d4d25dfbddadeaa542d461403 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:55:15 2018 +0800 Fix minor consistencies & redundant impl commit 124efdf7e66ee070fbcdde07ed4f20c717c9c1c0 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:40:14 2018 +0800 XML Docs commit 3aa5d363de335444558fdb4bf1bf48a5743bc917 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 18:22:46 2018 +0800 Add 'last modified' plugin Source: https://github.com/Still34/DocFx.Plugin.LastModified Licensed under MIT License commit 2014870dc05dedb6171338d8ae4329eaa4c73f90 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:57:40 2018 +0800 Fix letter-casing for files commit f27d659ebeb88348e24e759308933e3983831ad7 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:50:00 2018 +0800 Document exposed TypeReaders commit 5a824a5695d72a62e28e0a307a5be446557291be Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:44:15 2018 +0800 Add missing exceptions commit c2de0c055f3894c795ea7d7da774fb006c752898 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:40:16 2018 +0800 Fix seealso for preconditions and add missing descriptions commit 3a7d7ee9552a2c6fea1c32b6f3cd91f6efdd29f5 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:36:22 2018 +0800 Minor fixes in documentations + Fix unescaped '<' + Fix typo commit 45839bd982a822dd9da10ceb48989fdb2cd8cd85 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:29:47 2018 +0800 Add XML Docs commit 9e6254600cd7bb5b7626025492223717f92501f9 Merge: aea06788 bb4bb138 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 14:48:13 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit aea067884c81832ad6cd910ff56c550cf3ecad75 Merge: 27dc4831 9ddd7090 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:51:07 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit 27dc4831e88c952f3ea1f68b18434e16197fdfa9 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:50:27 2018 +0800 Add XML Docs commit baa8beb3824ed59fb50d269b9e13721fa9f5a04e Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:49:42 2018 +0800 Add XML Docs commit 089f97a0101a4ef9194f65b2d4435c0c69dfa87c Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:43:04 2018 +0800 Add details regarding userbot support commit bb4bb138460cc1e6bac53b4e838893dcfd812ce7 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Fri May 4 11:42:54 2018 +0100 Fix issues with #984, remove extraneous whitespace (#1051) - Removed unnecessary parameter in SocketVoiceServer - Moved SocketVoiceServer into Entities/Voice - Fixed a bug where trying to download the cached guild would throw - Fixed a potential bug where Discord might not give us a port when connecting to voice commit 9ddd70906aa01015fc76bc2401868e044c4c7cc1 Merge: f197174f 7cfed7ff Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:37:04 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit f197174fcc2df1e092b26cd2c8087b602ffb1960 Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:36:53 2018 +0800 Fix embed docs consistency commit 7cfed7ff67ac9aee517de4130d9ccf504791ed61 Author: Alex Gravely <tcbskater@hotmail.com> Date: Thu May 3 21:30:13 2018 -0400 Fix nullref when passing null to GetShardIdFor. (#1049) commit e775853b1b26eaf80e6e76c295b44ca6241eaee7 Author: Luke <dev@crimsonxv.pro> Date: Fri May 4 02:29:51 2018 +0100 Expose VoiceServerUpdate events (#984) * Expose VoiceServerUpdate events * Amend based on feedback * Move this out of guild entity * Fix namespace issue * Adjust based on feedback #2 * Use cacheable instead * Change based on feedback commit 157acc46955d52809b959b52fb1a04404a6df3a5 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 23:03:35 2018 +0800 Add tag examples commit 57ea571a8115f4b768c2dbbe1f2ef807b0cfd647 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:48:33 2018 +0800 Fix sample link & add missing pictures commit 6769c37ad7e664845948c50ce403217a9951ef07 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:39:26 2018 +0800 Compress some assets & add OAuth2 URL generator
7 years ago
Squashed commit of the following: commit dece19d89505342e5f8c51317b54be8ce69336c9 Merge: fdaa689a e764dafe Author: Still Hsu <341464@gmail.com> Date: Mon May 21 11:47:47 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit e764dafe083bf5db62091ac1f6b3d438eee38882 Author: Quahu <quahuu@gmail.com> Date: Sun May 13 15:34:40 2018 +0200 Add ViewChannel to Voice channel permissions (#1059) Previously, Voice channels did not have ViewChannel in their "all" permissions commit 32fc2df21b1840fd913ccce80c0686e8e853b43d Author: Alex Gravely <tcbskater@hotmail.com> Date: Sat May 12 20:47:44 2018 -0400 Remove unused field in EmbedFieldBuilder. (#1018) commit 39dffe858584d0e9eed750bff6426e9562db4262 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Sun May 13 01:46:07 2018 +0100 Audit Logs implementation (#1055) * Copy audit logs impl from old branch and clean up I suck at using git, so I'm gonna use brute force. * Remove unnecessary TODOs Category channels do not provide any new information, and the other I forgot to remove beforehand * Add invite update data, clean up after feedback * Remove TODOs, add WebhookType enum for future use WebhookType is a future-use type, as currently audit logs are the only thing which may return it. commit fdaa689ae8be8e9d2ff5190b6cfed5af244b805b Author: Still Hsu <341464@gmail.com> Date: Wed May 9 06:04:59 2018 +0800 Add explanation for RunMode commit ea82c2537e64d4b75f85d9369e90cb55cfcadcc7 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 16:30:48 2018 +0800 Initial proofread of the articles commit 124f1a267c663fbbb0f2dc23367dd910ae3ba4cc Merge: 25557218 97c89310 Author: Still Hsu <341464@gmail.com> Date: Tue May 8 05:02:01 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit 97c893107b51de24a38ea03c2f8260030c8fc7f5 Author: Still Hsu <341464@gmail.com> Date: Mon May 7 06:22:49 2018 +0800 Implement GetBanAsync (#1056) commit 25557218dbc9390dbeac108afc153776f52dc26f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 16:11:19 2018 +0800 Add details to SpotifyGame commit c7b236ddf5d7324dd8c1513ccd528a7a45d0031f Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:58:23 2018 +0800 Add more IGuild docs commit 1bb06cc37b7c2312b0ab111da63026a01da01e42 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:40:31 2018 +0800 Replace all langword placements with code block commit ac47d84ea74c81e136434dcc33967fe4cd95c1e6 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:22:17 2018 +0800 Replace langword null to code block null instead - Because DocFX sucks at rendering langword commit 0b15bbc54d15c036f770bab818712956c527b4ee Author: Still Hsu <341464@gmail.com> Date: Sun May 6 15:20:34 2018 +0800 Add XML docs commit 65d4e4360eb88e3bc5cc8f0da6135e5ee997af6c Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:57:53 2018 +0800 Add BaseSocketClient docs commit 8f64c045999c1bb0440bdc818f082e7459756b36 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:37:55 2018 +0800 Replace note block commit d8bb9e7aaa1e908ceb9227285c0cebec9add5280 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:31:50 2018 +0800 Add warning for bulk-delete endpoint commit adae5ffc9e42343f170d6c869644637587330b59 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:07:28 2018 +0800 Fix missing Username prop commit 3e591972cafdffb6692a1b94cf9a63251188df8b Author: Still Hsu <341464@gmail.com> Date: Sun May 6 06:01:34 2018 +0800 Add properties examples to overwrite commit 0ad66f6765addf6d4d25dfbddadeaa542d461403 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:55:15 2018 +0800 Fix minor consistencies & redundant impl commit 124efdf7e66ee070fbcdde07ed4f20c717c9c1c0 Author: Still Hsu <341464@gmail.com> Date: Sun May 6 04:40:14 2018 +0800 XML Docs commit 3aa5d363de335444558fdb4bf1bf48a5743bc917 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 18:22:46 2018 +0800 Add 'last modified' plugin Source: https://github.com/Still34/DocFx.Plugin.LastModified Licensed under MIT License commit 2014870dc05dedb6171338d8ae4329eaa4c73f90 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:57:40 2018 +0800 Fix letter-casing for files commit f27d659ebeb88348e24e759308933e3983831ad7 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:50:00 2018 +0800 Document exposed TypeReaders commit 5a824a5695d72a62e28e0a307a5be446557291be Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:44:15 2018 +0800 Add missing exceptions commit c2de0c055f3894c795ea7d7da774fb006c752898 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:40:16 2018 +0800 Fix seealso for preconditions and add missing descriptions commit 3a7d7ee9552a2c6fea1c32b6f3cd91f6efdd29f5 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:36:22 2018 +0800 Minor fixes in documentations + Fix unescaped '<' + Fix typo commit 45839bd982a822dd9da10ceb48989fdb2cd8cd85 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 15:29:47 2018 +0800 Add XML Docs commit 9e6254600cd7bb5b7626025492223717f92501f9 Merge: aea06788 bb4bb138 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 14:48:13 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit aea067884c81832ad6cd910ff56c550cf3ecad75 Merge: 27dc4831 9ddd7090 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:51:07 2018 +0800 Merge branch 'docs/faq-n-patches-offline' of https://github.com/Still34/Discord.Net into docs/faq-n-patches-offline commit 27dc4831e88c952f3ea1f68b18434e16197fdfa9 Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:50:27 2018 +0800 Add XML Docs commit baa8beb3824ed59fb50d269b9e13721fa9f5a04e Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:49:42 2018 +0800 Add XML Docs commit 089f97a0101a4ef9194f65b2d4435c0c69dfa87c Author: Still Hsu <341464@gmail.com> Date: Sat May 5 13:43:04 2018 +0800 Add details regarding userbot support commit bb4bb138460cc1e6bac53b4e838893dcfd812ce7 Author: Finite Reality <FiniteReality@users.noreply.github.com> Date: Fri May 4 11:42:54 2018 +0100 Fix issues with #984, remove extraneous whitespace (#1051) - Removed unnecessary parameter in SocketVoiceServer - Moved SocketVoiceServer into Entities/Voice - Fixed a bug where trying to download the cached guild would throw - Fixed a potential bug where Discord might not give us a port when connecting to voice commit 9ddd70906aa01015fc76bc2401868e044c4c7cc1 Merge: f197174f 7cfed7ff Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:37:04 2018 +0800 Merge branch 'dev' into docs/faq-n-patches-offline commit f197174fcc2df1e092b26cd2c8087b602ffb1960 Author: Still Hsu <341464@gmail.com> Date: Fri May 4 09:36:53 2018 +0800 Fix embed docs consistency commit 7cfed7ff67ac9aee517de4130d9ccf504791ed61 Author: Alex Gravely <tcbskater@hotmail.com> Date: Thu May 3 21:30:13 2018 -0400 Fix nullref when passing null to GetShardIdFor. (#1049) commit e775853b1b26eaf80e6e76c295b44ca6241eaee7 Author: Luke <dev@crimsonxv.pro> Date: Fri May 4 02:29:51 2018 +0100 Expose VoiceServerUpdate events (#984) * Expose VoiceServerUpdate events * Amend based on feedback * Move this out of guild entity * Fix namespace issue * Adjust based on feedback #2 * Use cacheable instead * Change based on feedback commit 157acc46955d52809b959b52fb1a04404a6df3a5 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 23:03:35 2018 +0800 Add tag examples commit 57ea571a8115f4b768c2dbbe1f2ef807b0cfd647 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:48:33 2018 +0800 Fix sample link & add missing pictures commit 6769c37ad7e664845948c50ce403217a9951ef07 Author: Still Hsu <341464@gmail.com> Date: Thu May 3 22:39:26 2018 +0800 Compress some assets & add OAuth2 URL generator
7 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ---
  2. uid: FAQ.Basics.BasicOp
  3. title: Questions about Basic Operations
  4. ---
  5. # Basic Operations Questions
  6. ## How should I safely check a type?
  7. > [!WARNING]
  8. > Direct casting (e.g., `(Type)type`) is **the least recommended**
  9. > way of casting, as it *can* throw an [InvalidCastException]
  10. > when the object isn't the desired type.
  11. >
  12. > Please refer to [this post] for more details.
  13. In Discord.Net, the idea of polymorphism is used throughout. You may
  14. need to cast the object as a certain type before you can perform any
  15. action.
  16. A good and safe casting example:
  17. [!code-csharp[Casting](samples/cast.cs)]
  18. [InvalidCastException]: https://docs.microsoft.com/en-us/dotnet/api/system.invalidcastexception
  19. [this post]: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-safely-cast-by-using-as-and-is-operators
  20. ## How do I send a message?
  21. > [!TIP]
  22. > The [GetChannel] method by default returns an [IChannel], allowing
  23. > channel types such as [IVoiceChannel], [ICategoryChannel]
  24. > to be returned; consequently, you cannot send a message
  25. > to channels like those.
  26. Any implementation of [IMessageChannel] has a [SendMessageAsync]
  27. method. You can get the channel via [GetChannel] under the client.
  28. Remember, when using Discord.Net, polymorphism is a common recurring
  29. theme. This means an object may take in many shapes or form, which
  30. means casting is your friend. You should attempt to cast the channel
  31. as an [IMessageChannel] or any other entity that implements it to be
  32. able to message.
  33. [SendMessageAsync]: xref:Discord.IMessageChannel.SendMessageAsync*
  34. [GetChannel]: xref:Discord.WebSocket.DiscordSocketClient.GetChannel*
  35. ## How can I tell if a message is from X, Y, Z channel?
  36. You may check the message channel type. Visit [Glossary] to see the
  37. various types of channels.
  38. [Glossary]: xref:FAQ.Misc.Glossary#message-channels
  39. ## How can I get the guild from a message?
  40. There are 2 ways to do this. You can do either of the following,
  41. 1. Cast the user as an [IGuildUser] and use its [IGuild] property.
  42. 2. Cast the channel as an [IGuildChannel] and use its [IGuild] property.
  43. ## How do I add hyperlink text to an embed?
  44. Embeds can use standard [markdown] in the description field as well
  45. as in field values. With that in mind, links can be added with
  46. `[text](link)`.
  47. [markdown]: https://support.discordapp.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-
  48. ## How do I add reactions to a message?
  49. Any entity that implements [IUserMessage] has an [AddReactionAsync]
  50. method. This method expects an [IEmote] as a parameter.
  51. In Discord.Net, an Emote represents a custom-image emote, while an
  52. Emoji is a Unicode emoji (standard emoji). Both [Emoji] and [Emote]
  53. implement [IEmote] and are valid options.
  54. [!code-csharp[Emoji](samples/emoji.cs)]
  55. [AddReactionAsync]: xref:Discord.IUserMessage.AddReactionAsync*
  56. ## What is a "preemptive rate limit?"
  57. A preemptive rate limit is Discord.Net's way of telling you to slow
  58. down before you get hit by the real rate limit. Hitting a real rate
  59. limit might prevent your entire client from sending any requests for
  60. a period of time. This is calculated based on the HTTP header
  61. returned by a Discord response.
  62. ## Why am I getting so many preemptive rate limits when I try to add more than one reactions?
  63. This is due to how HTML header works, mistreating
  64. 0.25sec/action to 1sec. This causes the lib to throw preemptive rate
  65. limit more frequently than it should for methods such as adding
  66. reactions.
  67. ## Can I opt-out of preemptive rate limits?
  68. Unfortunately, not at the moment. See [#401](https://github.com/RogueException/Discord.Net/issues/401).
  69. [IChannel]: xref:Discord.IChannel
  70. [ICategoryChannel]: xref:Discord.ICategoryChannel
  71. [IGuildChannel]: xref:Discord.IGuildChannel
  72. [ITextChannel]: xref:Discord.ITextChannel
  73. [IGuild]: xref:Discord.IGuild
  74. [IVoiceChannel]: xref:Discord.IVoiceChannel
  75. [IGuildUser]: xref:Discord.IGuildUser
  76. [IMessageChannel]: xref:Discord.IMessageChannel
  77. [IUserMessage]: xref:Discord.IUserMessage
  78. [IEmote]: xref:Discord.IEmote
  79. [Emote]: xref:Discord.Emote
  80. [Emoji]: xref:Discord.Emoji