From 685b2604e481cbcc5dd77aac21bbec9599aab0a5 Mon Sep 17 00:00:00 2001 From: Carter Date: Sun, 28 Mar 2021 21:51:42 -0600 Subject: [PATCH] docs: update docs and examples for #4879 (#5323) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- README.md | 4 ++-- docs/examples/attachments.md | 16 ++++++++-------- docs/examples/avatars.js | 4 ++-- docs/examples/embed.js | 4 ++-- docs/examples/greeting.js | 6 ++++-- docs/examples/moderation.md | 8 ++++---- docs/examples/ping.js | 4 ++-- docs/examples/webhook.js | 6 +++--- docs/general/welcome.md | 4 ++-- docs/topics/voice.md | 4 ++-- test/createGuild.js | 4 +--- test/random.js | 6 ++---- test/reactionCollectorCreated.test.js | 6 ++++-- test/sendtest.js | 10 ++++------ test/shard.js | 5 +++-- test/tester1000.js | 5 +++-- test/voice.js | 6 +++--- test/webhooktest.js | 12 +++++------- 18 files changed, 56 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 146ee1af1..a742d6b87 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ For production bots, using @discordjs/opus should be considered a necessity, esp ## Example usage ```js -const Discord = require('discord.js'); -const client = new Discord.Client(); +const { Client, Intents } = require('discord.js'); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); diff --git a/docs/examples/attachments.md b/docs/examples/attachments.md index 095160604..a77c9c801 100644 --- a/docs/examples/attachments.md +++ b/docs/examples/attachments.md @@ -10,10 +10,10 @@ The following examples use [MessageAttachment](/#/docs/main/master/class/Message ```js // Extract the required classes from the discord.js module -const { Client, MessageAttachment } = require('discord.js'); +const { Client, Intents, MessageAttachment } = require('discord.js'); // Create an instance of a Discord client -const client = new Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information @@ -45,10 +45,10 @@ But what if you want to send an attachment with a message content? Fear not, for ```js // Extract the required classes from the discord.js module -const { Client, MessageAttachment } = require('discord.js'); +const { Client, Intents, MessageAttachment } = require('discord.js'); // Create an instance of a Discord client -const client = new Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information @@ -82,10 +82,10 @@ Sending a local file isn't hard either! We'll be using [MessageAttachment](/#/do ```js // Extract the required classes from the discord.js module -const { Client, MessageAttachment } = require('discord.js'); +const { Client, Intents, MessageAttachment } = require('discord.js'); // Create an instance of a Discord client -const client = new Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information @@ -120,13 +120,13 @@ You can use any buffer you want, and send it. Just make sure to overwrite the fi ```js // Extract the required classes from the discord.js module -const { Client, MessageAttachment } = require('discord.js'); +const { Client, Intents, MessageAttachment } = require('discord.js'); // Import the native fs module const fs = require('fs'); // Create an instance of a Discord client -const client = new Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/avatars.js b/docs/examples/avatars.js index 6687033d7..9acaec307 100644 --- a/docs/examples/avatars.js +++ b/docs/examples/avatars.js @@ -5,10 +5,10 @@ */ // Import the discord.js module -const Discord = require('discord.js'); +const { Client, Intents } = require('discord.js'); // Create an instance of a Discord client -const client = new Discord.Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/embed.js b/docs/examples/embed.js index 05850fd7e..921982822 100644 --- a/docs/examples/embed.js +++ b/docs/examples/embed.js @@ -5,10 +5,10 @@ */ // Extract the required classes from the discord.js module -const { Client, MessageEmbed } = require('discord.js'); +const { Client, Intents, MessageEmbed } = require('discord.js'); // Create an instance of a Discord client -const client = new Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/greeting.js b/docs/examples/greeting.js index 1c0e35a21..32c304125 100644 --- a/docs/examples/greeting.js +++ b/docs/examples/greeting.js @@ -5,10 +5,12 @@ */ // Import the discord.js module -const Discord = require('discord.js'); +const { Client, Intents } = require('discord.js'); // Create an instance of a Discord client -const client = new Discord.Client(); +// Note: you __MUST__ have the GUILD_MEMBERS intent toggled on the dashboard +// see https://discordjs.guide/popular-topics/intents.html for more +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/moderation.md b/docs/examples/moderation.md index 30bc23f14..8e74eb2f1 100644 --- a/docs/examples/moderation.md +++ b/docs/examples/moderation.md @@ -8,10 +8,10 @@ Let's say you have a member that you'd like to kick. Here is an example of how y ```js // Import the discord.js module -const Discord = require('discord.js'); +const { Client, Intents } = require('discord.js'); // Create an instance of a Discord client -const client = new Discord.Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information @@ -80,10 +80,10 @@ Banning works the same way as kicking, but it has slightly more options that can ```js // Import the discord.js module -const Discord = require('discord.js'); +const { Client, Intents } = require('discord.js'); // Create an instance of a Discord client -const client = new Discord.Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/ping.js b/docs/examples/ping.js index cc6c78301..eff31c7fe 100644 --- a/docs/examples/ping.js +++ b/docs/examples/ping.js @@ -5,10 +5,10 @@ */ // Import the discord.js module -const Discord = require('discord.js'); +const { Client, Intents } = require('discord.js'); // Create an instance of a Discord client -const client = new Discord.Client(); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); /** * The ready event is vital, it means that only _after_ this will your bot start reacting to information diff --git a/docs/examples/webhook.js b/docs/examples/webhook.js index 1c74bfd8f..f66a4c3a2 100644 --- a/docs/examples/webhook.js +++ b/docs/examples/webhook.js @@ -5,15 +5,15 @@ */ // Import the discord.js module -const Discord = require('discord.js'); +const { WebhookClient } = require('discord.js'); /* * Create a new webhook * The Webhooks ID and token can be found in the URL, when you request that URL, or in the response body. * https://discord.com/api/webhooks/12345678910/T0kEn0fw3Bh00K - * ^^^^^^^^^^ ^^^^^^^^^^^^ + * ^^^^^^^^^^^ ^^^^^^^^^^^^^^ * Webhook ID Webhook Token */ -const hook = new Discord.WebhookClient('webhook id', 'webhook token'); +const hook = new WebhookClient('webhook id', 'webhook token'); // Send a message using the webhook hook.send('I am now alive!'); diff --git a/docs/general/welcome.md b/docs/general/welcome.md index 0dde0486e..ad4d6d1f1 100644 --- a/docs/general/welcome.md +++ b/docs/general/welcome.md @@ -59,8 +59,8 @@ For production bots, using @discordjs/opus should be considered a necessity, esp ## Example usage ```js -const Discord = require('discord.js'); -const client = new Discord.Client(); +const { Client, Intents } = require('discord.js'); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); diff --git a/docs/topics/voice.md b/docs/topics/voice.md index 8da936768..a15497bd1 100644 --- a/docs/topics/voice.md +++ b/docs/topics/voice.md @@ -22,8 +22,8 @@ The example below reacts to a message and joins the sender's voice channel, catc as it allows us to obtain a `VoiceConnection` that we can start to stream audio with. ```js -const Discord = require('discord.js'); -const client = new Discord.Client(); +const { Client, Intents } = require('discord.js'); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] }); client.login('token here'); diff --git a/test/createGuild.js b/test/createGuild.js index 287de2786..594e4c22f 100644 --- a/test/createGuild.js +++ b/test/createGuild.js @@ -4,9 +4,7 @@ const assert = require('assert'); const { token } = require('./auth'); const { Client, Intents } = require('../src'); -const client = new Client({ - intents: Intents.NON_PRIVILEGED, -}); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.on('ready', async () => { try { diff --git a/test/random.js b/test/random.js index d8d51e139..e09e23bb2 100644 --- a/test/random.js +++ b/test/random.js @@ -5,13 +5,11 @@ const request = require('superagent'); const ytdl = require('ytdl-core'); const { token, song } = require('./auth.js'); -const Discord = require('../src'); +const { Client, Intents } = require('../src'); console.time('magic'); -const client = new Discord.Client({ - intents: Discord.Intents.NON_PRIVILEGED -}); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS] }); client .login(token) diff --git a/test/reactionCollectorCreated.test.js b/test/reactionCollectorCreated.test.js index a9220e37b..46b379351 100644 --- a/test/reactionCollectorCreated.test.js +++ b/test/reactionCollectorCreated.test.js @@ -1,9 +1,11 @@ 'use strict'; const { token, guildId, channelId, messageId } = require('./auth.js'); -const { Client, ReactionCollector } = require('../src'); +const { Client, Intents, ReactionCollector } = require('../src'); -const client = new Client(); +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS], +}); client.on('ready', async () => { const guild = client.guilds.cache.get(guildId); diff --git a/test/sendtest.js b/test/sendtest.js index d5456d9c5..554698bc2 100644 --- a/test/sendtest.js +++ b/test/sendtest.js @@ -5,11 +5,9 @@ const path = require('path'); const util = require('util'); const fetch = require('node-fetch'); const { owner, token } = require('./auth.js'); -const Discord = require('../src'); +const { Client, Intents, MessageAttachment, MessageEmbed } = require('../src'); -const client = new Discord.Client({ - intents: Discord.Intents.NON_PRIVILEGED, -}); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const fill = c => Array(4).fill(c.repeat(1000)); const buffer = l => fetch(l).then(res => res.buffer()); @@ -21,8 +19,8 @@ const linkA = 'https://lolisafe.moe/iiDMtAXA.png'; const linkB = 'https://lolisafe.moe/9hSpedPh.png'; const fileA = path.join(__dirname, 'blobReach.png'); -const embed = () => new Discord.MessageEmbed(); -const attach = (attachment, name) => new Discord.MessageAttachment(attachment, name); +const embed = () => new MessageEmbed(); +const attach = (attachment, name) => new MessageAttachment(attachment, name); const tests = [ m => m.channel.send('x'), diff --git a/test/shard.js b/test/shard.js index 1dd1e89f8..fd113d664 100644 --- a/test/shard.js +++ b/test/shard.js @@ -1,9 +1,10 @@ 'use strict'; const { token } = require('./auth.json'); -const Discord = require('../src'); +const { Client, Intents } = require('../src'); -const client = new Discord.Client({ +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], shards: process.argv[2], shardCount: process.argv[3], intents: Discord.Intents.NON_PRIVILEGED, diff --git a/test/tester1000.js b/test/tester1000.js index 2705a4054..45deed3d2 100644 --- a/test/tester1000.js +++ b/test/tester1000.js @@ -1,12 +1,13 @@ 'use strict'; const { token, prefix, owner } = require('./auth.js'); -const Discord = require('../src'); +const { Client, Intents } = require('../src'); // eslint-disable-next-line no-console const log = (...args) => console.log(process.uptime().toFixed(3), ...args); -const client = new Discord.Client({ +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], shardCount: 2, intents: Discord.Intents.NON_PRIVILEGED, }); diff --git a/test/voice.js b/test/voice.js index cd7bc67ea..16b655dd7 100644 --- a/test/voice.js +++ b/test/voice.js @@ -3,11 +3,11 @@ const ytdl = require('ytdl-core'); const auth = require('./auth.js'); -const Discord = require('../src'); +const { Client, Intents } = require('../src'); -const client = new Discord.Client({ +const client = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_PRESENCES], partials: [], - intents: Discord.Intents.NON_PRIVILEGED, }); client diff --git a/test/webhooktest.js b/test/webhooktest.js index 74cb34a5d..2ac6ee927 100644 --- a/test/webhooktest.js +++ b/test/webhooktest.js @@ -5,11 +5,9 @@ const path = require('path'); const util = require('util'); const fetch = require('node-fetch'); const { owner, token, webhookChannel, webhookToken } = require('./auth.js'); -const Discord = require('../src'); +const { Client, Intents, MessageAttachment, MessageEmbed, WebhookClient } = require('../src'); -const client = new Discord.Client({ - intents: Discord.Intents.NON_PRIVILEGED, -}); +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const fill = c => Array(4).fill(c.repeat(1000)); const buffer = l => fetch(l).then(res => res.buffer()); @@ -21,8 +19,8 @@ const linkA = 'https://lolisafe.moe/iiDMtAXA.png'; const linkB = 'https://lolisafe.moe/9hSpedPh.png'; const fileA = path.join(__dirname, 'blobReach.png'); -const embed = () => new Discord.MessageEmbed(); -const attach = (attachment, name) => new Discord.MessageAttachment(attachment, name); +const embed = () => new MessageEmbed(); +const attach = (attachment, name) => new MessageAttachment(attachment, name); const tests = [ (m, hook) => hook.send('x'), @@ -121,7 +119,7 @@ client.on('message', async message => { if (message.author.id !== owner) return; const match = message.content.match(/^do (.+)$/); const hooks = [ - { type: 'WebhookClient', hook: new Discord.WebhookClient(webhookChannel, webhookToken) }, + { type: 'WebhookClient', hook: new WebhookClient(webhookChannel, webhookToken) }, { type: 'TextChannel#fetchWebhooks', hook: await message.channel.fetchWebhooks().then(x => x.first()) }, { type: 'Guild#fetchWebhooks', hook: await message.guild.fetchWebhooks().then(x => x.first()) }, ];