Skip to content

Commit

Permalink
refactor(popular-topics): prefer enum usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Feb 18, 2024
1 parent 44c0c48 commit 2bbfd92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
16 changes: 10 additions & 6 deletions guide/popular-topics/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ If you would like to set your activity upon startup, you can use the `ClientOpti
### How do I make my bot display online/idle/dnd/invisible?

```js
client.user.setStatus('online');
client.user.setStatus('idle');
client.user.setStatus('dnd');
client.user.setStatus('invisible');
const { PresenceUpdateStatus } = require('discord.js');

client.user.setStatus(PresenceUpdateStatus.Online);
client.user.setStatus(PresenceUpdateStatus.Idle);
client.user.setStatus(PresenceUpdateStatus.DoNotDisturb);
client.user.setStatus(PresenceUpdateStatus.Invisible);
```

### How do I set both status and activity in one go?

```js
client.user.setPresence({ activities: [{ name: 'activity' }], status: 'idle' });
const { PresenceUpdateStatus } = require('discord.js');

client.user.setPresence({ activities: [{ name: 'activity' }], status: PresenceUpdateStatus.Idle });
```

## Miscellaneous
Expand Down Expand Up @@ -269,7 +273,7 @@ A User represents a global Discord user, and a GuildMember represents a Discord
```js
// First use guild.members.fetch to make sure all members are cached
guild.members.fetch({ withPresences: true }).then(fetchedMembers => {
const totalOnline = fetchedMembers.filter(member => member.presence?.status === 'online');
const totalOnline = fetchedMembers.filter(member => member.presence?.status === PresenceUpdateStatus.Online);
// Now you have a collection with all online member objects in the totalOnline variable
console.log(`There are currently ${totalOnline.size} members online in this guild!`);
});
Expand Down
8 changes: 4 additions & 4 deletions guide/popular-topics/formatters.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ discord.js provides the <PackageLink name="formatters" /> package which contains
These functions format strings into all the different Markdown styles supported by Discord.

```js
const { bold, italic, strikethrough, underscore, spoiler, quote, blockQuote } = require('discord.js');
const { bold, italic, strikethrough, underline, spoiler, quote, blockQuote } = require('discord.js');
const string = 'Hello!';

const boldString = bold(string);
const italicString = italic(string);
const strikethroughString = strikethrough(string);
const underscoreString = underscore(string);
const underlineString = underline(string);
const spoilerString = spoiler(string);
const quoteString = quote(string);
const blockquoteString = blockQuote(string);
Expand Down Expand Up @@ -49,11 +49,11 @@ const highlighted = codeBlock('js', jsString);
With `time()`, you can format Unix timestamps and dates into a Discord time string.

```js
const { time } = require('discord.js');
const { time, TimestampStyles } = require('discord.js');
const date = new Date();

const timeString = time(date);
const relative = time(date, 'R');
const relative = time(date, TimestampStyles.RelativeTime);
```

## Mentions
Expand Down
10 changes: 5 additions & 5 deletions guide/popular-topics/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To create a thread you call the <DocsLink path="class/GuildTextThreadManager?scr
```js
const thread = await channel.threads.create({
name: 'food-talk',
autoArchiveDuration: 60,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
reason: 'Needed a separate thread for food',
});

Expand Down Expand Up @@ -99,7 +99,7 @@ Public threads are viewable by everyone who can view the parent channel of the t
```js
const thread = await channel.threads.create({
name: 'food-talk',
autoArchiveDuration: 60,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
reason: 'Needed a separate thread for food',
});

Expand All @@ -113,7 +113,7 @@ They can also be created from an existing message with the <DocsLink path="class
```js
const thread = await message.startThread({
name: 'food-talk',
autoArchiveDuration: 60,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
reason: 'Needed a separate thread for food',
});

Expand All @@ -129,11 +129,11 @@ To create a private thread, use <DocsLink path="class/GuildTextThreadManager?scr
<!-- eslint-skip -->

```js {6}
const { ChannelType } = require('discord.js');
const { ChannelType, ThreadAutoArchiveDuration } = require('discord.js');

const thread = await channel.threads.create({
name: 'mod-talk',
autoArchiveDuration: 60,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
type: ChannelType.PrivateThread,
reason: 'Needed a separate thread for moderation',
});
Expand Down

0 comments on commit 2bbfd92

Please sign in to comment.