docs: update docs and examples for #4879 (#5323)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
Carter
2021-03-28 21:51:42 -06:00
committed by GitHub
parent 624a4464ca
commit 685b2604e4
18 changed files with 56 additions and 58 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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!');

View File

@@ -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}!`);

View File

@@ -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');