You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/additional-info/rest-api.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -179,7 +179,7 @@ If you've followed the tutorial, you should have something like this:
179
179
</discord-message>
180
180
</div>
181
181
182
-
Now, let's just make this an [embed](/popular-topics/miscellaneous-examples.md#sending-an-embed).
182
+
Now, let's just make this an [embed](/popular-topics/embeds.md).
183
183
184
184
We are also going to be defining a utility function at the top of our file so that our embed doesn't error when the field value is over 1024 characters. Here is a bit of code to do that:
*`<client>` is a placeholder for the Client object, such as `const client = new Discord.Client();`.
6
6
*`<message>` is a placeholder for the Message object, such as `client.on('message', message => { ... });`.
7
7
*`<guild>` is a placeholder for the Guild object, such as `<message>.guild` or <branchversion="12.x"inline>`<client>.guilds.cache.get('<id>')`</branch><branchversion="11.x"inline>`<client>.guilds.get('<id>')`</branch>.
8
+
*`<voiceChannel>` is a placeholder for the VoiceChannel object, such as <branchversion="11.x"inline>`<message>.member.voiceChannel`</branch><branchversion="12.x"inline>`<message>.member.voice.channel`</branch>
8
9
9
10
For a more detailed explanation on the notations commonly used in this guide, the docs, and the support server, see [here](/additional-info/notation.md).
10
11
@@ -131,17 +132,17 @@ if (<message>.author.id === '<id>') {
131
132
}
132
133
```
133
134
134
-
## Bot Configuration
135
+
## Bot Configuration and Utility
135
136
136
-
### How do I set my username?
137
+
### How do I set my bot's username?
137
138
138
139
<!-- eslint-skip -->
139
140
140
141
```js
141
142
<client>.user.setUsername('<username>');
142
143
```
143
144
144
-
### How do I set my avatar?
145
+
### How do I set my bot's avatar?
145
146
146
147
<!-- eslint-skip -->
147
148
@@ -169,11 +170,11 @@ if (<message>.author.id === '<id>') {
169
170
<branchversion="11.x">
170
171
171
172
::: tip
172
-
If you would like to set your activity upon startup, you must place the `<client>.user.setActivity()` method in a `ready` event listener (`<client>.on('ready', () => {});`).
173
+
If you would like to set your activity upon startup, you must place the `<client>.user.setActivity()` method call inside a `ready` event listener (`<client>.on('ready', () => {});`).
173
174
:::
174
175
175
176
::: warning
176
-
`<client>.user.setActivity()` will only work in v11.3 and above. You can check your version with `npm ls discord.js` and update with `npm install discord.js`. You can still use `<client>.user.setGame()`, but it is deprecated as of v11.3, and has been removed in v12.
177
+
`<client>.user.setActivity()` will only work in v11.3 and above. You can still use `<client>.user.setGame()`, but it is deprecated as of v11.3, and has been removed in v12.
177
178
:::
178
179
179
180
</branch>
@@ -185,9 +186,72 @@ If you would like to set your activity upon startup, you can use the `ClientOpti
185
186
186
187
</branch>
187
188
189
+
### How do I make my bot display online/idle/dnd/invisible?
190
+
191
+
<!-- eslint-skip -->
192
+
193
+
```js
194
+
<client>.user.setStatus('online');
195
+
<client>.user.setStatus('idle');
196
+
<client>.user.setStatus('dnd');
197
+
<client>.user.setStatus('invisible');
198
+
```
199
+
200
+
### How do I set both status and activity in one go?
the `activity` key will only work in v11.3 and above. You can still use the `game` key instead, but it is deprecated as of v11.3, and has been removed in v12.
message.reply(`you can either ping me or use \`${prefix}\` as my prefix.`);
238
+
}
239
+
});
240
+
241
+
client.login('your-token-goes-here');
242
+
```
243
+
244
+
::: tip
245
+
The `escapeRegex` function is used to convert special characters into literal characters by escaping them, so that they don't terminate the pattern within the [Regular Expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)!
246
+
:::
247
+
248
+
::: tip
249
+
If you aren't familiar with the syntax used on the `const [, matchedPrefix] = ...` line, that's called "array destructuring". Feel free to read more about it in the [ES6 syntax](/additional-info/es6-syntax.md#array-destructuring) guide!
250
+
:::
251
+
188
252
## Miscellaneous
189
253
190
-
### How do I send a message to a certain channel?
254
+
### How do I send a message to a specific channel?
191
255
192
256
<branchversion="11.x">
193
257
@@ -237,7 +301,7 @@ user.send('<content>');
237
301
If you want to DM the user who sent the message, you can use `<message>.author.send()`.
238
302
:::
239
303
240
-
### How do I tag a certain user in a message?
304
+
### How do I mention a certain user in a message?
241
305
242
306
<!-- eslint-skip -->
243
307
@@ -248,11 +312,7 @@ const user = <message>.mentions.users.first();
248
312
```
249
313
250
314
::: tip
251
-
If you want to tag the user who sent the message, you can use `<message>.reply()`. For example: `<message>.reply('hi.')` would result in `@User, hi.`. If you want to insert the tag elsewhere, you can store `<message>.author` as your `user` variable and use the original example.
252
-
:::
253
-
254
-
::: tip
255
-
Tags inside certain areas of an embed may display correctly, but will not actually ping the user. Tags inside other certain areas of an embed will display the raw string instead (e.g. `<@123456789012345678>`).
315
+
Mentions in embeds may resolve correctly but will never notify the user. Some areas of embeds do not support mentions at all.
256
316
:::
257
317
258
318
### How do I prompt the user for additional input?
@@ -297,7 +357,7 @@ Tags inside certain areas of an embed may display correctly, but will not actual
297
357
</branch>
298
358
299
359
::: tip
300
-
If you want to learn more about this syntax or want to learn about reaction collectors as well, check out [this dedicated guide page for collectors](/popular-topics/collectors.md)!
360
+
If you want to learn more about this syntax or reaction collectors, check out [this dedicated guide page for collectors](/popular-topics/collectors.md)!
301
361
:::
302
362
303
363
### How do I react to the message my bot sent?
@@ -315,7 +375,7 @@ If you want to learn more about this syntax or want to learn about reaction coll
315
375
If you want to learn more about reactions, check out [this dedicated guide on reactions](/popular-topics/reactions.md)!
316
376
:::
317
377
318
-
### How do I create a restart command?
378
+
### How do I restart my bot with a command?
319
379
320
380
```js
321
381
process.exit();
@@ -325,28 +385,22 @@ process.exit();
325
385
`process.exit()` will only kill your Node process, but when using [PM2](http://pm2.keymetrics.io/), it will restart the process whenever it gets killed. You can read our guide on PM2 [here](/improving-dev-environment/pm2.md).
326
386
:::
327
387
328
-
::: warning
329
-
Be sure to [limit this to your own ID](/popular-topics/common-questions.md#how-do-i-limit-a-command-to-a-single-user) so that other users can't restart your bot!
330
-
:::
331
-
332
388
### What is the difference between a User and a GuildMember?
333
389
334
-
A lot of users get confused as to what the difference between Users and GuildMembers is. The simple answer is that a User represents a global Discord user and a GuildMember represents a Discord user on a specific server. That means only GuildMembers can have permissions, roles, and nicknames, for example, because all of these things are server-bound information that could be different on each server that user is in.
335
-
336
-
### How do I find all online members?
390
+
A User represents a global Discord user and a GuildMember represents a Discord user on a specific server. That means only GuildMembers can have permissions, roles, and nicknames, for example, because all of these things are server-bound information that could be different on each server that user is in.
337
391
338
-
Assuming the process is to be done for the guild the message is sent in.
392
+
### How do I find all online members of a guild?
339
393
340
394
<branchversion="11.x">
341
395
342
396
<!-- eslint-skip -->
343
397
344
398
```js
345
399
// First we use fetchMembers to make sure all members are cached
If you've tried using [the usual method of retrieving unicode emojis](/popular-topics/reactions.md#unicode-emojis), you may have noticed that some characters don't provide the expected results. Here's a short snippet that'll help with that issue. You can toss this into a file of its own and use it anywhere you need! Alternatively feel free to simply copy-paste the characters from below:
On Windows, you may be able to use the `Win + .` keyboard shortcut to open up an emoji picker can be used for quick, easy access to all the unicode emojis available to you. Some of the emojis listed above may not be represented there, though (e.g the 0-9 emojis).
0 commit comments