chore: general cleanup (#5661)

This commit is contained in:
Noel
2021-05-22 11:40:30 +02:00
committed by GitHub
parent 03256bd9f8
commit f8703e3e59
22 changed files with 12259 additions and 1825 deletions

View File

@@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@master uses: actions/checkout@v2
- name: Install Node v14 - name: Install Node v14
uses: actions/setup-node@master uses: actions/setup-node@v2
with: with:
node-version: 14 node-version: 14

View File

@@ -19,7 +19,7 @@ jobs:
run: npm ci run: npm ci
- name: Run ESLint - name: Run ESLint
uses: icrawl/action-eslint@v1 run: npm run lint
typings: typings:
name: TSLint name: TSLint

View File

@@ -17,7 +17,7 @@ jobs:
run: npm ci run: npm ci
- name: Run ESLint - name: Run ESLint
uses: icrawl/action-eslint@v1 run: npm run lint
typings: typings:
name: TSLint name: TSLint

1
.husky/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_

4
.husky/commit-msg Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit $1

5
.husky/pre-commit Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint:fix
npx --no-install pretty-quick --staged

3
.npmrc Normal file
View File

@@ -0,0 +1,3 @@
audit=false
fund=false
legacy-peer-deps=true

View File

@@ -1,163 +0,0 @@
# Sending Attachments
In here you'll see a few examples showing how you can send an attachment using discord.js.
## Sending an attachment using a URL
There are a few ways you can do this, but we'll show you the easiest.
The following examples use [MessageAttachment](/#/docs/main/master/class/MessageAttachment).
```js
// Extract the required classes from the discord.js module
const { Client, Intents, MessageAttachment } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// If the message is '!rip'
if (message.content === '!rip') {
// Create the attachment using MessageAttachment
const attachment = new MessageAttachment('https://i.imgur.com/w3duR07.png');
// Send the attachment in the message channel
message.channel.send(attachment);
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
And here is the result:
![Image showing the result](/static/attachment-example1.png)
But what if you want to send an attachment with a message content? Fear not, for it is easy to do that too! We'll recommend reading [the TextChannel's "send" function documentation](/#/docs/main/master/class/TextChannel?scrollTo=send) to see what other options are available.
```js
// Extract the required classes from the discord.js module
const { Client, Intents, MessageAttachment } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// If the message is '!rip'
if (message.content === '!rip') {
// Create the attachment using MessageAttachment
const attachment = new MessageAttachment('https://i.imgur.com/w3duR07.png');
// Send the attachment in the message channel with a content
message.channel.send(`${message.author},`, attachment);
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
And here's the result of this one:
![Image showing the result](/static/attachment-example2.png)
## Sending a local file or buffer
Sending a local file isn't hard either! We'll be using [MessageAttachment](/#/docs/main/master/class/MessageAttachment) for these examples too.
```js
// Extract the required classes from the discord.js module
const { Client, Intents, MessageAttachment } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// If the message is '!rip'
if (message.content === '!rip') {
// Create the attachment using MessageAttachment
const attachment = new MessageAttachment('./rip.png');
// Send the attachment in the message channel with a content
message.channel.send(`${message.author},`, attachment);
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
The results are the same as the URL examples:
![Image showing result](/static/attachment-example2.png)
But what if you have a buffer from an image? Or a text document? Well, it's the same as sending a local file or a URL!
In the following example, we'll be getting the buffer from a `memes.txt` file, and send it in the message channel.
You can use any buffer you want, and send it. Just make sure to overwrite the filename if it isn't an image!
```js
// Extract the required classes from the discord.js module
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({ 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// If the message is '!memes'
if (message.content === '!memes') {
// Get the buffer from the 'memes.txt', assuming that the file exists
const buffer = fs.readFileSync('./memes.txt');
/**
* Create the attachment using MessageAttachment,
* overwritting the default file name to 'memes.txt'
* Read more about it over at
* http://discord.js.org/#/docs/main/master/class/MessageAttachment
*/
const attachment = new MessageAttachment(buffer, 'memes.txt');
// Send the attachment in the message channel with a content
message.channel.send(`${message.author}, here are your memes!`, attachment);
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
And of course, the results are:
![Attachment File example 3](/static/attachment-example3.png)

View File

@@ -1,31 +0,0 @@
'use strict';
/**
* Send a user a link to their avatar
*/
// Import the discord.js module
const { Client, Intents } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
// Create an event listener for messages
client.on('message', message => {
// If the message is "what is my avatar"
if (message.content === 'what is my avatar') {
// Send the user's avatar URL
message.channel.send(message.author.displayAvatarURL());
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');

View File

@@ -1,52 +0,0 @@
# Slash Commands
In this example, you'll get to know how to create commands and listen to incoming interactions.
## Creating a Command
First off, we need to create a command so that users can use it. We will create an `echo` command which simply returns what the user inputted. Note that global commands can take up to an hour to appear in the client, so if you want to test a new command, you should create it for one guild first.
```js
// The data for our command
const commandData = {
name: 'echo',
description: 'Replies with your input!',
options: [{
name: 'input',
type: 'STRING',
description: 'The input which should be echoed back',
required: true,
}],
};
client.once('ready', () => {
// Creating a global command
client.application.commands.create(commandData);
// Creating a guild-specific command
client.guilds.cache.get('id').commands.create(commandData);
});
```
And that's it! As soon as your client is ready, it will register the `echo` command.
## Handling Commands
Now let's implement a simple handler for it:
```js
client.on('interaction', interaction => {
// If the interaction isn't a slash command, return
if (!interaction.isCommand()) return;
// Check if it is the correct command
if (interaction.commandName === 'echo') {
// Get the input of the user
const input = interaction.options[0].value;
// Reply to the command
interaction.reply(input);
}
});
```
The `interaction` event will get emitted every time the client receives an interaction. Only our own slash commands trigger this event, so there is no need to implement a check for commands that belong to other bots.

View File

@@ -1,40 +0,0 @@
'use strict';
/**
* An example of how you can send embeds
*/
// Extract the required classes from the discord.js module
const { Client, Intents, MessageEmbed } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// If the message is "how to embed"
if (message.content === 'how to embed') {
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/master/class/MessageEmbed
const embed = new MessageEmbed()
// Set the title of the field
.setTitle('A slick little embed')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Hello, this is a slick embed!');
// Send the embed to the same channel as the message
message.channel.send(embed);
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');

View File

@@ -1,34 +0,0 @@
'use strict';
/**
* A bot that welcomes new guild members when they join
*/
// Import the discord.js module
const { Client, Intents } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
// Create an event listener for new guild members
client.on('guildMemberAdd', member => {
// Send the message to a designated channel on a server:
const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}`);
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');

View File

@@ -1,151 +0,0 @@
# Moderation
In here, you'll see some basic examples for kicking and banning a member.
## Kicking a member
Let's say you have a member that you'd like to kick. Here is an example of how you _can_ do it.
```js
// Import the discord.js module
const { Client, Intents } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
// If the message content starts with "!kick"
if (message.content.startsWith('!kick')) {
// Assuming we mention someone in the message, this will return the user
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
const user = message.mentions.users.first();
// If we have a user mentioned
if (user) {
// Now we get the member from the user
const member = message.guild.members.resolve(user);
// If the member is in the guild
if (member) {
/**
* Kick the member
* Make sure you run this on a member, not a user!
* There are big differences between a user and a member
*/
member
.kick('Optional reason that will display in the audit logs')
.then(() => {
// We let the message author know we were able to kick the person
message.channel.send(`Successfully kicked ${user.tag}`);
})
.catch(err => {
// An error happened
// This is generally due to the bot not being able to kick the member,
// either due to missing permissions or role hierarchy
message.channel.send('I was unable to kick the member');
// Log the error
console.error(err);
});
} else {
// The mentioned user isn't in this guild
message.channel.send("That user isn't in this guild!");
}
// Otherwise, if no user was mentioned
} else {
message.channel.send("You didn't mention the user to kick!");
}
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
And the result is:
![Image showing the result](/static/kick-example.png)
## Banning a member
Banning works the same way as kicking, but it has slightly more options that can be changed.
```js
// Import the discord.js module
const { Client, Intents } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
// if the message content starts with "!ban"
if (message.content.startsWith('!ban')) {
// Assuming we mention someone in the message, this will return the user
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
const user = message.mentions.users.first();
// If we have a user mentioned
if (user) {
// Now we get the member from the user
const member = message.guild.members.resolve(user);
// If the member is in the guild
if (member) {
/**
* Ban the member
* Make sure you run this on a member, not a user!
* There are big differences between a user and a member
* Read more about what ban options there are over at
* https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
*/
member
.ban({
reason: 'They were bad!',
})
.then(() => {
// We let the message author know we were able to ban the person
message.channel.send(`Successfully banned ${user.tag}`);
})
.catch(err => {
// An error happened
// This is generally due to the bot not being able to ban the member,
// either due to missing permissions or role hierarchy
message.channel.send('I was unable to ban the member');
// Log the error
console.error(err);
});
} else {
// The mentioned user isn't in this guild
message.channel.send("That user isn't in this guild!");
}
} else {
// Otherwise, if no user was mentioned
message.channel.send("You didn't mention the user to ban!");
}
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');
```
And the result is:
![Image showing the result](/static/ban-example.png)

View File

@@ -1,31 +0,0 @@
'use strict';
/**
* A ping pong bot, whenever you send "ping", it replies "pong".
*/
// Import the discord.js module
const { Client, Intents } = require('discord.js');
// Create an instance of a 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
* received from Discord
*/
client.on('ready', () => {
console.log('I am ready!');
});
// Create an event listener for messages
client.on('message', message => {
// If the message is "ping"
if (message.content === 'ping') {
// Send "pong" to the same channel
message.channel.send('pong');
}
});
// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');

View File

@@ -1,19 +0,0 @@
'use strict';
/**
* Send a message using a webhook
*/
// Import the discord.js module
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 WebhookClient('webhook id', 'webhook token');
// Send a message using the webhook
hook.send('I am now alive!');

View File

@@ -2,10 +2,6 @@
These questions are some of the most frequently asked. These questions are some of the most frequently asked.
## No matter what, I get `SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode`‽
Update to Node.js 14.0.0 or newer.
## How do I get voice working? ## How do I get voice working?
- Install FFMPEG. - Install FFMPEG.
@@ -15,9 +11,9 @@ Update to Node.js 14.0.0 or newer.
## How do I install FFMPEG? ## How do I install FFMPEG?
- **npm:** `npm install ffmpeg-static` - **npm:** `npm install ffmpeg-static`
- **Ubuntu 16.04:** `sudo apt install ffmpeg` - **Ubuntu 20.04:** `sudo apt install ffmpeg`
- **Ubuntu 14.04:** `sudo apt-get install libav-tools` - **Ubuntu 18.04:** `sudo apt install ffmpeg`
- **Windows:** `npm install ffmpeg-static` or see the [FFMPEG section of AoDude's guide](https://github.com/bdistin/OhGodMusicBot/blob/master/README.md#download-ffmpeg). - **Windows:** `npm install ffmpeg-static` or see [WikiHow](https://www.wikihow.com/Install-FFmpeg-on-Windows).
## How do I set up @discordjs/opus? ## How do I set up @discordjs/opus?
@@ -26,5 +22,5 @@ Update to Node.js 14.0.0 or newer.
Then, running `npm install @discordjs/opus` in your bot's directory should successfully build it. Woo! Then, running `npm install @discordjs/opus` in your bot's directory should successfully build it. Woo!
Other questions can be found at the [official Discord.js guide](https://discordjs.guide/popular-topics/faq.html) Other questions can be found at the [official Discord.js guide](https://discordjs.guide/popular-topics/faq.html)
If you have issues not listed here or on the guide, feel free to ask in the [official Discord.js server](https://discord.gg/bRCvFy9). If you have issues not listed here or on the guide, feel free to ask in the [official Discord.js server](https://discord.gg/djs).
Always make sure to read the [documentation](https://discord.js.org/#/docs/main/stable/general/welcome). Always make sure to read the [documentation](https://discord.js.org/#/docs/main/stable/general/welcome).

View File

@@ -1,195 +0,0 @@
# Version 12.0.0
v12.0.0 contains many new and improved features, optimisations, and bug fixes.
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/12.0.0) for a full list of changes.
You can also visit [the guide](https://discordjs.guide/additional-info/changes-in-v12.html) for help with updating your v11 code to v12.
# Version 11.1.0
v11.1.0 features improved voice and gateway stability, as well as support for new features such as audit logs and searching for messages.
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.1.0) for a full list of changes, including
information about deprecations.
# Version 11
Version 11 contains loads of new and improved features, optimisations, and bug fixes.
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.0.0) for a full list of changes.
## Significant additions
- Message Reactions and Embeds (rich text)
- Support for uws and erlpack for better performance
- OAuthApplication support
- Web distributions
## Breaking changes
### Client.login() no longer supports logging in with email + password
Logging in with an email and password has always been heavily discouraged since the advent of proper token support, but in v11 we have made the decision to completely remove the functionality, since Hammer & Chisel have [officially stated](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862) it simply shouldn't be done.
User accounts can still log in with tokens just like bot accounts. To obtain the token for a user account, you can log in to Discord with that account, and use Ctrl + Shift + I to open the developer tools. In the console tab, evaluating `localStorage.token` will give you the token for that account.
### ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts
Since you can no longer log in with email and password, you must provide the current account password to the `setEmail()`, `setPassword()`, and `setUsername()` methods for user accounts (self-bots).
### Removed TextBasedChannel.sendTTSMessage()
This method was deemed to be an entirely pointless shortcut that virtually nobody even used.
The same results can be achieved by passing options to `send()` or `sendMessage()`.
Example:
```js
channel.send('Hi there', { tts: true });
```
### Using Collection.find()/exists() with IDs will throw an error
This is simply to help prevent a common mistake that is made frequently.
To find something or check its existence using an ID, you should use `.get()` and `.has()` which are part of the [ES6 Map class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map), which Collection is an extension of.
# Version 10
Version 10's non-BC changes focus on cleaning up some inconsistencies that exist in previous versions.
Upgrading from v9 should be quick and painless.
## Client options
All client options have been converted to camelCase rather than snake_case, and `max_message_cache` was renamed to `messageCacheMaxSize`.
v9 code example:
```js
const client = new Discord.Client({
disable_everyone: true,
max_message_cache: 500,
message_cache_lifetime: 120,
message_sweep_interval: 60,
});
```
v10 code example:
```js
const client = new Discord.Client({
disableEveryone: true,
messageCacheMaxSize: 500,
messageCacheLifetime: 120,
messageSweepInterval: 60,
});
```
## Presences
Presences have been completely restructured.
Previous versions of discord.js assumed that users had the same presence amongst all guilds - with the introduction of sharding, however, this is no longer the case.
v9 discord.js code may look something like this:
```js
User.status; // the status of the user
User.game; // the game that the user is playing
ClientUser.setStatus(status, game, url); // set the new status for the user
```
v10 moves presences to GuildMember instances. For the sake of simplicity, though, User classes also expose presences.
When accessing a presence on a User object, it simply finds the first GuildMember for the user, and uses its presence.
Additionally, the introduction of the Presence class keeps all of the presence data organised.
**It is strongly recommended that you use a GuildMember's presence where available, rather than a User.
A user may have an entirely different presence between two different guilds.**
v10 code:
```js
MemberOrUser.presence.status; // the status of the member or user
MemberOrUser.presence.game; // the game that the member or user is playing
ClientUser.setStatus(status); // online, idle, dnd, offline
ClientUser.setGame(game, streamingURL); // a game
ClientUser.setPresence(fullPresence); // status and game combined
```
## Voice
Voice has been rewritten internally, but in a backwards-compatible manner.
There is only one breaking change here; the `disconnected` event was renamed to `disconnect`.
Several more events have been made available to a VoiceConnection, so see the documentation.
## Events
Many events have been renamed or had their arguments change.
### Client events
| Version 9 | Version 10 |
| ---------------------------------------------- | --------------------------------------- |
| guildMemberAdd(guild, member) | guildMemberAdd(member) |
| guildMemberAvailable(guild, member) | guildMemberAvailable(member) |
| guildMemberRemove(guild, member) | guildMemberRemove(member) |
| guildMembersChunk(guild, members) | guildMembersChunk(members) |
| guildMemberUpdate(guild, oldMember, newMember) | guildMemberUpdate(oldMember, newMember) |
| guildRoleCreate(guild, role) | roleCreate(role) |
| guildRoleDelete(guild, role) | roleDelete(role) |
| guildRoleUpdate(guild, oldRole, newRole) | roleUpdate(oldRole, newRole) |
The guild parameter that has been dropped from the guild-related events can still be derived using `member.guild` or `role.guild`.
### VoiceConnection events
| Version 9 | Version 10 |
| ------------ | ---------- |
| disconnected | disconnect |
## Dates and timestamps
All dates/timestamps on the structures have been refactored to have a consistent naming scheme and availability.
All of them are named similarly to this:
**Date:** `Message.createdAt`
**Timestamp:** `Message.createdTimestamp`
See the docs for each structure to see which date/timestamps are available on them.
# Version 9
The version 9 (v9) rewrite takes a much more object-oriented approach than previous versions,
which allows your code to be much more readable and manageable.
It's been rebuilt from the ground up and should be much more stable, fixing caching issues that affected
older versions. It also has support for newer Discord Features, such as emojis.
Version 9, while containing a sizable number of breaking changes, does not require much change in your code's logic -
most of the concepts are still the same, but loads of functions have been moved around.
The vast majority of methods you're used to using have been moved out of the Client class,
into other more relevant classes where they belong.
Because of this, you will need to convert most of your calls over to the new methods.
Here are a few examples of methods that have changed:
- `Client.sendMessage(channel, message)` ==> `TextChannel.sendMessage(message)`
- `Client.sendMessage(user, message)` ==> `User.sendMessage(message)`
- `Client.updateMessage(message, "New content")` ==> `Message.edit("New Content")`
- `Client.getChannelLogs(channel, limit)` ==> `TextChannel.fetchMessages({options})`
- `Server.detailsOfUser(User)` ==> `Server.members.get(User).properties` (retrieving a member gives a GuildMember object)
- `Client.joinVoiceChannel(voicechannel)` => `VoiceChannel.join()`
A couple more important details:
- `Client.loginWithToken("token")` ==> `client.login("token")`
- `Client.servers.length` ==> `client.guilds.size` (all instances of `server` are now `guild`)
## No more callbacks!
Version 9 eschews callbacks in favour of Promises. This means all code relying on callbacks must be changed.
For example, the following code:
```js
client.getChannelLogs(channel, 100, function(messages) {
console.log(`${messages.length} messages found`);
});
```
```js
channel.fetchMessages({ limit: 100 }).then(messages => {
console.log(`${messages.size} messages found`);
});
```

View File

@@ -2,8 +2,6 @@
files: files:
- name: Welcome - name: Welcome
path: welcome.md path: welcome.md
- name: Updating your code
path: updating.md
- name: FAQ - name: FAQ
path: faq.md path: faq.md
- name: Topics - name: Topics
@@ -12,21 +10,3 @@
path: voice.md path: voice.md
- name: Partials - name: Partials
path: partials.md path: partials.md
- name: Examples
files:
- name: Ping
path: ping.js
- name: Avatars
path: avatars.js
- name: Attachments
path: attachments.md
- name: Server greeting
path: greeting.js
- name: Message Embed
path: embed.js
- name: Moderation
path: moderation.md
- name: Webhook
path: webhook.js
- name: Slash Commands
path: commands.md

13249
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "discord.js", "name": "discord.js",
"version": "12.5.0", "version": "13.0.0-dev",
"description": "A powerful library for interacting with the Discord API", "description": "A powerful library for interacting with the Discord API",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",
@@ -23,7 +23,8 @@
"lint:fix": "eslint src --fix", "lint:fix": "eslint src --fix",
"lint:typings": "tslint typings/index.d.ts", "lint:typings": "tslint typings/index.d.ts",
"prettier": "prettier --write src/**/*.js typings/**/*.ts", "prettier": "prettier --write src/**/*.js typings/**/*.ts",
"prepublishOnly": "npm run test" "prepublishOnly": "npm run test",
"prepare": "husky install"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -49,44 +50,33 @@
"@discordjs/form-data": "^3.0.1", "@discordjs/form-data": "^3.0.1",
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"prism-media": "^1.2.2", "prism-media": "^1.2.9",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
"ws": "^7.3.1" "ws": "^7.4.5"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^11.0.0", "@commitlint/cli": "^12.1.4",
"@commitlint/config-angular": "^11.0.0", "@commitlint/config-angular": "^12.1.4",
"@discordjs/docgen": "^0.10.0",
"@types/node": "^12.12.6", "@types/node": "^12.12.6",
"@types/ws": "^7.2.7", "@types/ws": "^7.4.4",
"cross-env": "^7.0.2", "cross-env": "^7.0.3",
"discord-api-types": "^0.18.1", "discord-api-types": "^0.18.1",
"discord.js-docgen": "git+https://github.com/discordjs/docgen.git", "dtslint": "^4.0.9",
"dtslint": "^4.0.4", "eslint": "^7.27.0",
"eslint": "^7.11.0", "eslint-config-prettier": "^8.3.0",
"eslint-config-prettier": "^6.13.0", "eslint-plugin-import": "^2.23.3",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^3.1.4", "husky": "^6.0.0",
"husky": "^4.3.0", "jest": "^26.6.3",
"jest": "^26.6.0", "prettier": "^2.3.0",
"json-filter-loader": "^1.0.0", "pretty-quick": "^3.1.0",
"lint-staged": "^10.4.2",
"prettier": "^2.1.2",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"typescript": "^4.2.4" "typescript": "^4.2.4"
}, },
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=14.0.0"
}, },
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.js": "eslint --fix",
"*.ts": "prettier --write"
},
"commitlint": { "commitlint": {
"extends": [ "extends": [
"@commitlint/config-angular" "@commitlint/config-angular"

View File

@@ -93,18 +93,8 @@ class GuildChannelManager extends BaseManager {
* }) * })
*/ */
async create(name, options = {}) { async create(name, options = {}) {
let { let { type, topic, nsfw, bitrate, userLimit, parent, permissionOverwrites, position, rateLimitPerUser, reason } =
type, options;
topic,
nsfw,
bitrate,
userLimit,
parent,
permissionOverwrites,
position,
rateLimitPerUser,
reason,
} = options;
if (parent) parent = this.client.channels.resolveID(parent); if (parent) parent = this.client.channels.resolveID(parent);
if (permissionOverwrites) { if (permissionOverwrites) {
permissionOverwrites = permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild)); permissionOverwrites = permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));

4
typings/index.d.ts vendored
View File

@@ -461,9 +461,7 @@ declare module 'discord.js' {
Endpoints: { Endpoints: {
botGateway: string; botGateway: string;
invite: (root: string, code: string) => string; invite: (root: string, code: string) => string;
CDN: ( CDN: (root: string) => {
root: string,
) => {
Asset: (name: string) => string; Asset: (name: string) => string;
DefaultAvatar: (id: string | number) => string; DefaultAvatar: (id: string | number) => string;
Emoji: (emojiID: string, format: 'png' | 'gif') => string; Emoji: (emojiID: string, format: 'png' | 'gif') => string;