mirror of
https://github.com/danbulant/discord.js
synced 2026-06-24 17:21:59 +00:00
Compare commits
72 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eaafaf1d3 | ||
|
|
c513df444e | ||
|
|
4f5cdf2814 | ||
|
|
0ca50889ae | ||
|
|
53412f6b9f | ||
|
|
2b8a6294af | ||
|
|
8c65961a07 | ||
|
|
4599ef954f | ||
|
|
790b6b3b5c | ||
|
|
5be32161b9 | ||
|
|
db6d1b3ba9 | ||
|
|
21bfe3da7c | ||
|
|
a626dc8c41 | ||
|
|
c6f87aa32d | ||
|
|
2685b960d7 | ||
|
|
60e5a0e46f | ||
|
|
7365f40300 | ||
|
|
09d07553ab | ||
|
|
e272fd6909 | ||
|
|
90d458820b | ||
|
|
9f3c3e0918 | ||
|
|
ec560b8107 | ||
|
|
fbb1c93454 | ||
|
|
6b322f47a0 | ||
|
|
4fcb9ebf30 | ||
|
|
53529bd05d | ||
|
|
88625a5b7d | ||
|
|
e43ad1eea9 | ||
|
|
8d650a7250 | ||
|
|
12a096b5f1 | ||
|
|
6f3076325e | ||
|
|
8c8883ef26 | ||
|
|
4b555fdf4c | ||
|
|
863734aba4 | ||
|
|
1f4b9fe749 | ||
|
|
2a6c363a8a | ||
|
|
643f96c79b | ||
|
|
2b2994badc | ||
|
|
eaecd0e8b7 | ||
|
|
2e940e635d | ||
|
|
8b91ac5d7e | ||
|
|
7faa73a561 | ||
|
|
eadeeed72e | ||
|
|
939c495ebb | ||
|
|
042e071a64 | ||
|
|
065e89337e | ||
|
|
1028183c23 | ||
|
|
b61a367392 | ||
|
|
ff2dbfa52d | ||
|
|
3463acafca | ||
|
|
274ae9935e | ||
|
|
2eafeeca55 | ||
|
|
b8fd3f65d9 | ||
|
|
efd7849ed0 | ||
|
|
adf2e872f8 | ||
|
|
ed8b3cc9ea | ||
|
|
7ec0bd93b0 | ||
|
|
3d158f4448 | ||
|
|
250c3ae3c1 | ||
|
|
08286459cb | ||
|
|
2e96b9a606 | ||
|
|
ef1856bb1f | ||
|
|
4f7c207c99 | ||
|
|
975b6cbd94 | ||
|
|
67c2e56647 | ||
|
|
ab0d6fc5c9 | ||
|
|
b8f50a09d2 | ||
|
|
9f3108052c | ||
|
|
a5ce6cfa9a | ||
|
|
ab5ee838a3 | ||
|
|
0ed281888d | ||
|
|
bc4dc22c1f |
66 changed files with 1475 additions and 456 deletions
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"root": true,
|
||||
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
|
||||
"plugins": ["import"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2019
|
||||
"ecmaVersion": 2020
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"es2020": true,
|
||||
"node": true
|
||||
},
|
||||
"overrides": [{ "files": ["*.browser.js"], "env": { "browser": true } }],
|
||||
|
|
|
|||
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
|
|
@ -11,7 +11,7 @@ is a great boon to your development process.
|
|||
To get ready to work on the codebase, please do the following:
|
||||
|
||||
1. Fork & clone the repository, and make sure you're on the **master** branch
|
||||
2. Run `npm install`
|
||||
2. Run `npm ci`
|
||||
3. If you're working on voice, also run `npm install @discordjs/opus` or `npm install opusscript`
|
||||
4. Code your heart out!
|
||||
5. Run `npm test` to run ESLint and ensure any JSDoc changes are valid
|
||||
|
|
|
|||
8
.github/workflows/deploy.yml
vendored
8
.github/workflows/deploy.yml
vendored
|
|
@ -15,10 +15,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -35,10 +35,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
|
|||
16
.github/workflows/test-cron.yml
vendored
16
.github/workflows/test-cron.yml
vendored
|
|
@ -10,10 +10,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -28,10 +28,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -46,10 +46,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -67,10 +67,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
|
|||
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
|
|
@ -8,10 +8,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -26,10 +26,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -44,10 +44,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
@ -65,10 +65,10 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
- name: Install Node v14
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 14
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
## Table of contents
|
||||
|
||||
- [Changes](#changes)
|
||||
- [About](#about)
|
||||
- [Installation](#installation)
|
||||
- [Audio engines](#audio-engines)
|
||||
|
|
@ -29,6 +30,10 @@
|
|||
- [Contributing](#contributing)
|
||||
- [Help](#help)
|
||||
|
||||
## Changes
|
||||
|
||||
This fork has the inline replies and slash commands for **testing** purposes.
|
||||
|
||||
## About
|
||||
|
||||
discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to easily interact with the
|
||||
|
|
@ -41,7 +46,7 @@ discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to
|
|||
|
||||
## Installation
|
||||
|
||||
**Node.js 12.0.0 or newer is required.**
|
||||
**Node.js 14.0.0 or newer is required.**
|
||||
Ignore any warnings about unmet peer dependencies, as they're all optional.
|
||||
|
||||
Without voice support: `npm install discord.js`
|
||||
|
|
@ -76,7 +81,7 @@ client.on('ready', () => {
|
|||
|
||||
client.on('message', msg => {
|
||||
if (msg.content === 'ping') {
|
||||
msg.reply('pong');
|
||||
msg.channel.send('pong');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ 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.reply(message.author.displayAvatarURL());
|
||||
message.channel.send(message.author.displayAvatarURL());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ client.on('message', message => {
|
|||
// If we have a user mentioned
|
||||
if (user) {
|
||||
// Now we get the member from the user
|
||||
const member = message.guild.member(user);
|
||||
const member = message.guild.members.resolve(user);
|
||||
// If the member is in the guild
|
||||
if (member) {
|
||||
/**
|
||||
|
|
@ -45,23 +45,23 @@ client.on('message', message => {
|
|||
.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.reply(`Successfully kicked ${user.tag}`);
|
||||
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.reply('I was unable to kick the member');
|
||||
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.reply("That user isn't in this guild!");
|
||||
message.channel.send("That user isn't in this guild!");
|
||||
}
|
||||
// Otherwise, if no user was mentioned
|
||||
} else {
|
||||
message.reply("You didn't mention the user to kick!");
|
||||
message.channel.send("You didn't mention the user to kick!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -105,7 +105,7 @@ client.on('message', message => {
|
|||
// If we have a user mentioned
|
||||
if (user) {
|
||||
// Now we get the member from the user
|
||||
const member = message.guild.member(user);
|
||||
const member = message.guild.members.resolve(user);
|
||||
// If the member is in the guild
|
||||
if (member) {
|
||||
/**
|
||||
|
|
@ -121,23 +121,23 @@ client.on('message', message => {
|
|||
})
|
||||
.then(() => {
|
||||
// We let the message author know we were able to ban the person
|
||||
message.reply(`Successfully banned ${user.tag}`);
|
||||
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.reply('I was unable to ban the member');
|
||||
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.reply("That user isn't in this guild!");
|
||||
message.channel.send("That user isn't in this guild!");
|
||||
}
|
||||
} else {
|
||||
// Otherwise, if no user was mentioned
|
||||
message.reply("You didn't mention the user to ban!");
|
||||
message.channel.send("You didn't mention the user to ban!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ 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 12.0.0 or newer.
|
||||
Update to Node.js 14.0.0 or newer.
|
||||
|
||||
## How do I get voice working?
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to
|
|||
|
||||
## Installation
|
||||
|
||||
**Node.js 12.0.0 or newer is required.**
|
||||
**Node.js 14.0.0 or newer is required.**
|
||||
Ignore any warnings about unmet peer dependencies, as they're all optional.
|
||||
|
||||
Without voice support: `npm install discord.js`
|
||||
|
|
@ -68,7 +68,7 @@ client.on('ready', () => {
|
|||
|
||||
client.on('message', msg => {
|
||||
if (msg.content === 'ping') {
|
||||
msg.reply('pong');
|
||||
msg.channel.send('pong');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ client.on('message', async message => {
|
|||
if (message.member.voice.channel) {
|
||||
const connection = await message.member.voice.channel.join();
|
||||
} else {
|
||||
message.reply('You need to join a voice channel first!');
|
||||
message.channel.send('You need to join a voice channel first!');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export const {
|
|||
UserFlags,
|
||||
Util,
|
||||
version,
|
||||
BaseGuildEmojiManager,
|
||||
ChannelManager,
|
||||
GuildChannelManager,
|
||||
GuildEmojiManager,
|
||||
|
|
@ -65,6 +66,7 @@ export const {
|
|||
GuildEmoji,
|
||||
GuildMember,
|
||||
GuildPreview,
|
||||
GuildTemplate,
|
||||
Integration,
|
||||
Invite,
|
||||
Message,
|
||||
|
|
|
|||
51
package-lock.json
generated
51
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "discord.js",
|
||||
"version": "12.4.0",
|
||||
"version": "12.5.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
@ -2506,9 +2506,9 @@
|
|||
"optional": true
|
||||
},
|
||||
"collect-all": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/collect-all/-/collect-all-1.0.3.tgz",
|
||||
"integrity": "sha512-0y0rBgoX8IzIjBAUnO73SEtSb4Mhk3IoceWJq5zZSxb9mWORhWH8xLYo4EDSOE1jRBk1LhmfjqWFFt10h/+MEA==",
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/collect-all/-/collect-all-1.0.4.tgz",
|
||||
"integrity": "sha512-RKZhRwJtJEP5FWul+gkSMEnaK6H3AGPTTWOiRimCcs+rc/OmQE3Yhy1Q7A7KsdkG3ZXVdZq68Y6ONSdvkeEcKA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"stream-connect": "^1.0.2",
|
||||
|
|
@ -3136,8 +3136,8 @@
|
|||
}
|
||||
},
|
||||
"discord.js-docgen": {
|
||||
"version": "github:discordjs/docgen#54934d3e46546f014e93f605399c5a0c0906d62c",
|
||||
"from": "github:discordjs/docgen",
|
||||
"version": "git+https://github.com/discordjs/docgen.git#d40f54cfd2d0f03ff92d7ecfb29cd82694ee2c11",
|
||||
"from": "git+https://github.com/discordjs/docgen.git",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"eslint": "^6.3.0",
|
||||
|
|
@ -4207,13 +4207,32 @@
|
|||
}
|
||||
},
|
||||
"eslint-scope": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz",
|
||||
"integrity": "sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==",
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
|
||||
"integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"esrecurse": "^4.1.0",
|
||||
"esrecurse": "^4.3.0",
|
||||
"estraverse": "^4.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"esrecurse": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
|
||||
"integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"estraverse": "^5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"estraverse": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz",
|
||||
"integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"eslint-utils": {
|
||||
|
|
@ -6461,9 +6480,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"jsdoc": {
|
||||
"version": "3.6.5",
|
||||
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.5.tgz",
|
||||
"integrity": "sha512-SbY+i9ONuxSK35cgVHaI8O9senTE4CDYAmGSDJ5l3+sfe62Ff4gy96osy6OW84t4K4A8iGnMrlRrsSItSNp3RQ==",
|
||||
"version": "3.6.6",
|
||||
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.6.tgz",
|
||||
"integrity": "sha512-znR99e1BHeyEkSvgDDpX0sTiTu+8aQyDl9DawrkOGZTTW8hv0deIFXx87114zJ7gRaDZKVQD/4tr1ifmJp9xhQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/parser": "^7.9.4",
|
||||
|
|
@ -10123,9 +10142,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.10.1",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.10.1.tgz",
|
||||
"integrity": "sha512-RjxApKkrPJB6kjJxQS3iZlf///REXWYxYJxO/MpmlQzVkDWVI3PSnCBWezMecmTU/TRkNxrl8bmsfFQCp+LO+Q==",
|
||||
"version": "3.11.4",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.11.4.tgz",
|
||||
"integrity": "sha512-FyYnoxVL1D6+jDGQpbK5jW6y/2JlVfRfEeQ67BPCUg5wfCjaKOpr2XeceE4QL+MkhxliLtf5EbrMDZgzpt2CNw==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "discord.js",
|
||||
"version": "12.4.0",
|
||||
"version": "12.5.0",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"main": "./src/index",
|
||||
"types": "./typings/index.d.ts",
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
"@types/node": "^12.12.6",
|
||||
"@types/ws": "^7.2.7",
|
||||
"cross-env": "^7.0.2",
|
||||
"discord.js-docgen": "discordjs/docgen",
|
||||
"discord.js-docgen": "git+https://github.com/discordjs/docgen.git",
|
||||
"dtslint": "^4.0.4",
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-config-prettier": "^6.13.0",
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"browser": {
|
||||
"@discordjs/opus": false,
|
||||
|
|
@ -110,9 +110,9 @@
|
|||
"src/client/voice/receiver/PacketHandler.js": false,
|
||||
"src/client/voice/receiver/Receiver.js": false,
|
||||
"src/client/voice/util/PlayInterface.js": false,
|
||||
"src/client/voice/util/Secretbox.js": false,
|
||||
"src/client/voice/util/Silence.js": false,
|
||||
"src/client/voice/util/VolumeInterface.js": false
|
||||
"src/client/voice/util/VolumeInterface.js": false,
|
||||
"src/util/Sodium.js": false
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const BaseClient = require('./BaseClient');
|
||||
const InteractionClient = require('./InteractionClient');
|
||||
const ActionsManager = require('./actions/ActionsManager');
|
||||
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
||||
const WebSocketManager = require('./websocket/WebSocketManager');
|
||||
const { Error, TypeError, RangeError } = require('../errors');
|
||||
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
||||
const ChannelManager = require('../managers/ChannelManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientApplication = require('../structures/ClientApplication');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
const VoiceRegion = require('../structures/VoiceRegion');
|
||||
const Webhook = require('../structures/Webhook');
|
||||
|
|
@ -102,6 +104,12 @@ class Client extends BaseClient {
|
|||
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
||||
: null;
|
||||
|
||||
/**
|
||||
* The interaction client.
|
||||
* @type {InteractionClient}
|
||||
*/
|
||||
this.interactionClient = new InteractionClient(options, this);
|
||||
|
||||
/**
|
||||
* All of the {@link User} objects that have been cached at any point, mapped by their IDs
|
||||
* @type {UserManager}
|
||||
|
|
@ -165,11 +173,11 @@ class Client extends BaseClient {
|
|||
|
||||
/**
|
||||
* All custom emojis that the client has access to, mapped by their IDs
|
||||
* @type {GuildEmojiManager}
|
||||
* @type {BaseGuildEmojiManager}
|
||||
* @readonly
|
||||
*/
|
||||
get emojis() {
|
||||
const emojis = new GuildEmojiManager({ client: this });
|
||||
const emojis = new BaseGuildEmojiManager(this);
|
||||
for (const guild of this.guilds.cache.values()) {
|
||||
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
||||
}
|
||||
|
|
@ -254,6 +262,23 @@ class Client extends BaseClient {
|
|||
.then(data => new Invite(this, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a template from Discord.
|
||||
* @param {GuildTemplateResolvable} template Template code or URL
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
* @example
|
||||
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
|
||||
* .then(template => console.log(`Obtained template with code: ${template.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchGuildTemplate(template) {
|
||||
const code = DataResolver.resolveGuildTemplateCode(template);
|
||||
return this.api.guilds
|
||||
.templates(code)
|
||||
.get()
|
||||
.then(data => new GuildTemplate(this, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a webhook from Discord.
|
||||
* @param {Snowflake} id ID of the webhook
|
||||
|
|
|
|||
207
src/client/InteractionClient.js
Normal file
207
src/client/InteractionClient.js
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
'use strict';
|
||||
|
||||
const BaseClient = require('./BaseClient');
|
||||
const ApplicationCommand = require('../structures/ApplicationCommand');
|
||||
const Interaction = require('../structures/Interaction');
|
||||
const { Events, ApplicationCommandOptionType, InteractionType, InteractionResponseType } = require('../util/Constants');
|
||||
|
||||
let sodium;
|
||||
|
||||
/**
|
||||
* Interaction client is used for interactions.
|
||||
*
|
||||
* @example
|
||||
* const client = new InteractionClient({
|
||||
* token: ABC,
|
||||
* publicKey: XYZ,
|
||||
* });
|
||||
*
|
||||
* client.on('interactionCreate', () => {
|
||||
* // automatically handles long responses
|
||||
* if (will take a long time) {
|
||||
* doSomethingLong.then((d) => {
|
||||
* interaction.reply({
|
||||
* content: 'wow that took long',
|
||||
* });
|
||||
* });
|
||||
* } else {
|
||||
* interaction.reply('hi!');
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
class InteractionClient extends BaseClient {
|
||||
/**
|
||||
* @param {Options} options Options for the client.
|
||||
* @param {undefined} client For internal use.
|
||||
*/
|
||||
constructor(options, client) {
|
||||
super(options);
|
||||
|
||||
Object.defineProperty(this, 'token', {
|
||||
value: options.token,
|
||||
writable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'clientID', {
|
||||
value: options.clientID,
|
||||
writable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(this, 'publicKey', {
|
||||
value: options.publicKey ? Buffer.from(options.publicKey, 'hex') : undefined,
|
||||
writable: true,
|
||||
});
|
||||
|
||||
// Compat for direct usage
|
||||
this.client = client || this;
|
||||
this.interactionClient = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get registered slash commands.
|
||||
* @param {Snowflake} [guildID] Optional guild ID.
|
||||
* @returns {Command[]}
|
||||
*/
|
||||
async getCommands(guildID) {
|
||||
let path = this.client.api.applications('@me');
|
||||
if (guildID) {
|
||||
path = path.guilds(guildID);
|
||||
}
|
||||
const commands = await path.commands.get();
|
||||
return commands.map(c => new ApplicationCommand(this, c, guildID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a command.
|
||||
* @param {Object} command The command description.
|
||||
* @param {Snowflake?} guildID Optional guild ID.
|
||||
* @returns {Promise<ApplicationCommand>} The created command.
|
||||
*/
|
||||
async createCommand(command, guildID) {
|
||||
let path = this.client.api.applications(this.client.user.id);
|
||||
if (guildID) {
|
||||
path = path.guilds(guildID);
|
||||
}
|
||||
const c = await path.commands.post({
|
||||
data: {
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
options: command.options.map(function m(o) {
|
||||
return {
|
||||
type: ApplicationCommandOptionType[o.type],
|
||||
name: o.name,
|
||||
description: o.description,
|
||||
default: o.default,
|
||||
required: o.required,
|
||||
choices: o.choices,
|
||||
options: o.options ? o.options.map(m) : undefined,
|
||||
};
|
||||
}),
|
||||
},
|
||||
});
|
||||
return new ApplicationCommand(this, c, guildID);
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
switch (data.type) {
|
||||
case InteractionType.PING:
|
||||
return {
|
||||
type: InteractionResponseType.PONG,
|
||||
};
|
||||
case InteractionType.APPLICATION_COMMAND: {
|
||||
let timedOut = false;
|
||||
let resolve;
|
||||
const directPromise = new Promise(r => {
|
||||
resolve = r;
|
||||
this.client.setTimeout(() => {
|
||||
timedOut = true;
|
||||
r({
|
||||
type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE,
|
||||
});
|
||||
}, 250);
|
||||
});
|
||||
|
||||
const syncHandle = {
|
||||
acknowledge() {
|
||||
if (!timedOut) {
|
||||
resolve({
|
||||
type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE,
|
||||
});
|
||||
}
|
||||
},
|
||||
reply(resolved) {
|
||||
if (timedOut) {
|
||||
return false;
|
||||
}
|
||||
resolve({
|
||||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
|
||||
data: resolved.data,
|
||||
});
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
const interaction = new Interaction(this.client, data, syncHandle);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interactionCreate
|
||||
* @param {Interaction} interaction The interaction which was created.
|
||||
*/
|
||||
this.client.emit(Events.INTERACTION_CREATE, interaction);
|
||||
|
||||
return directPromise;
|
||||
}
|
||||
default:
|
||||
throw new RangeError('Invalid interaction data');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An express-like middleware factory which can be used
|
||||
* with webhook interactions.
|
||||
* @returns {Function} The middleware function.
|
||||
*/
|
||||
middleware() {
|
||||
return async (req, res) => {
|
||||
const timestamp = req.get('x-signature-timestamp');
|
||||
const signature = req.get('x-signature-ed25519');
|
||||
|
||||
const chunks = [];
|
||||
for await (const chunk of req) {
|
||||
chunks.push(chunk);
|
||||
}
|
||||
const body = Buffer.concat(chunks);
|
||||
|
||||
if (sodium === undefined) {
|
||||
sodium = require('../util/Sodium');
|
||||
}
|
||||
if (
|
||||
!sodium.methods.verify(
|
||||
Buffer.from(signature, 'hex'),
|
||||
Buffer.concat([Buffer.from(timestamp), body]),
|
||||
this.publicKey,
|
||||
)
|
||||
) {
|
||||
res.status(403).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = JSON.parse(body.toString());
|
||||
|
||||
const result = await this.handle(data);
|
||||
res.status(200).end(JSON.stringify(result));
|
||||
};
|
||||
}
|
||||
|
||||
async handleFromGateway(data) {
|
||||
const result = await this.handle(data);
|
||||
|
||||
await this.client.api.interactions(data.id, data.token).callback.post({
|
||||
data: result,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InteractionClient;
|
||||
|
|
@ -93,8 +93,9 @@ class GenericAction {
|
|||
if (data.guild_id && data.member && data.member.user) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const member = this.getMember(data.member, guild);
|
||||
return member ? member.user : undefined;
|
||||
return guild.members.add(data.member).user;
|
||||
} else {
|
||||
return this.client.users.add(data.member.user);
|
||||
}
|
||||
}
|
||||
return this.getUser(data);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class ActionsManager {
|
|||
this.register(require('./InviteCreate'));
|
||||
this.register(require('./InviteDelete'));
|
||||
this.register(require('./GuildMemberRemove'));
|
||||
this.register(require('./GuildMemberUpdate'));
|
||||
this.register(require('./GuildBanRemove'));
|
||||
this.register(require('./GuildRoleCreate'));
|
||||
this.register(require('./GuildRoleDelete'));
|
||||
|
|
@ -36,6 +37,7 @@ class ActionsManager {
|
|||
this.register(require('./GuildIntegrationsUpdate'));
|
||||
this.register(require('./WebhooksUpdate'));
|
||||
this.register(require('./TypingStart'));
|
||||
this.register(require('./InteractionCreate'));
|
||||
}
|
||||
|
||||
register(Action) {
|
||||
|
|
|
|||
44
src/client/actions/GuildMemberUpdate.js
Normal file
44
src/client/actions/GuildMemberUpdate.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Status, Events } = require('../../util/Constants');
|
||||
|
||||
class GuildMemberUpdateAction extends Action {
|
||||
handle(data, shard) {
|
||||
const { client } = this;
|
||||
if (data.user.username) {
|
||||
const user = client.users.cache.get(data.user.id);
|
||||
if (!user) {
|
||||
client.users.add(data.user);
|
||||
} else if (!user.equals(data.user)) {
|
||||
client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
}
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const member = this.getMember({ user: data.user }, guild);
|
||||
if (member) {
|
||||
const old = member._update(data);
|
||||
/**
|
||||
* Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
|
||||
* Also emitted when the user's details (e.g. username) change.
|
||||
* @event Client#guildMemberUpdate
|
||||
* @param {GuildMember} oldMember The member before the update
|
||||
* @param {GuildMember} newMember The member after the update
|
||||
*/
|
||||
if (shard.status === Status.READY) client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
|
||||
} else {
|
||||
const newMember = guild.members.add(data);
|
||||
/**
|
||||
* Emitted whenever a member becomes available in a large guild.
|
||||
* @event Client#guildMemberAvailable
|
||||
* @param {GuildMember} member The member that became available
|
||||
*/
|
||||
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, newMember);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildMemberUpdateAction;
|
||||
15
src/client/actions/InteractionCreate.js
Normal file
15
src/client/actions/InteractionCreate.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class InteractionCreateAction extends Action {
|
||||
handle(data) {
|
||||
this.client.interactionClient.handleFromGateway(data).catch(e => {
|
||||
this.client.emit('error', e);
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InteractionCreateAction;
|
||||
|
|
@ -8,7 +8,10 @@ const { PartialTypes } = require('../../util/Constants');
|
|||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id' } }
|
||||
channel_id: 'id',
|
||||
// If originating from a guild
|
||||
guild_id: 'id',
|
||||
member: { ..., user: { ... } } }
|
||||
*/
|
||||
|
||||
class MessageReactionAdd extends Action {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ const { Events } = require('../../util/Constants');
|
|||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id' } }
|
||||
channel_id: 'id',
|
||||
guild_id: 'id' }
|
||||
*/
|
||||
|
||||
class MessageReactionRemove extends Action {
|
||||
|
|
|
|||
|
|
@ -473,7 +473,11 @@ class VoiceConnection extends EventEmitter {
|
|||
}
|
||||
|
||||
onStartSpeaking({ user_id, ssrc, speaking }) {
|
||||
this.ssrcMap.set(+ssrc, { userID: user_id, speaking: speaking });
|
||||
this.ssrcMap.set(+ssrc, {
|
||||
...(this.ssrcMap.get(+ssrc) || {}),
|
||||
userID: user_id,
|
||||
speaking: speaking,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -501,7 +505,7 @@ class VoiceConnection extends EventEmitter {
|
|||
}
|
||||
|
||||
if (guild && user && !speaking.equals(old)) {
|
||||
const member = guild.member(user);
|
||||
const member = guild.members.resolve(user);
|
||||
if (member) {
|
||||
/**
|
||||
* Emitted once a guild member changes speaking state.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const { Writable } = require('stream');
|
||||
const secretbox = require('../util/Secretbox');
|
||||
const secretbox = require('../../../util/Sodium');
|
||||
const Silence = require('../util/Silence');
|
||||
const VolumeInterface = require('../util/VolumeInterface');
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,11 @@ class VoiceWebSocket extends EventEmitter {
|
|||
this.emit('sessionDescription', packet.d);
|
||||
break;
|
||||
case VoiceOPCodes.CLIENT_CONNECT:
|
||||
this.connection.ssrcMap.set(+packet.d.audio_ssrc, { userID: packet.d.user_id, speaking: 0 });
|
||||
this.connection.ssrcMap.set(+packet.d.audio_ssrc, {
|
||||
userID: packet.d.user_id,
|
||||
speaking: 0,
|
||||
hasVideo: Boolean(packet.d.video_ssrc),
|
||||
});
|
||||
break;
|
||||
case VoiceOPCodes.CLIENT_DISCONNECT:
|
||||
const streamInfo = this.connection.receiver && this.connection.receiver.packets.streams.get(packet.d.user_id);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const secretbox = require('../util/Secretbox');
|
||||
const sodium = require('../../../util/Sodium');
|
||||
const Speaking = require('../../../util/Speaking');
|
||||
const { SILENCE_FRAME } = require('../util/Silence');
|
||||
|
||||
// The delay between packets when a user is considered to have stopped speaking
|
||||
// https://github.com/discordjs/discord.js/issues/3524#issuecomment-540373200
|
||||
|
|
@ -56,7 +58,7 @@ class PacketHandler extends EventEmitter {
|
|||
}
|
||||
|
||||
// Open packet
|
||||
let packet = secretbox.methods.open(buffer.slice(12, end), this.nonce, secret_key);
|
||||
let packet = sodium.methods.open(buffer.slice(12, end), this.nonce, secret_key);
|
||||
if (!packet) return new Error('Failed to decrypt voice packet');
|
||||
packet = Buffer.from(packet);
|
||||
|
||||
|
|
@ -84,12 +86,30 @@ class PacketHandler extends EventEmitter {
|
|||
const userStat = this.connection.ssrcMap.get(ssrc);
|
||||
if (!userStat) return;
|
||||
|
||||
let opusPacket;
|
||||
const streamInfo = this.streams.get(userStat.userID);
|
||||
// If the user is in video, we need to check if the packet is just silence
|
||||
if (userStat.hasVideo) {
|
||||
opusPacket = this.parseBuffer(buffer);
|
||||
if (opusPacket instanceof Error) {
|
||||
// Only emit an error if we were actively receiving packets from this user
|
||||
if (streamInfo) {
|
||||
this.emit('error', opusPacket);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (SILENCE_FRAME.equals(opusPacket)) {
|
||||
// If this is a silence frame, pretend we never received it
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let speakingTimeout = this.speakingTimeouts.get(ssrc);
|
||||
if (typeof speakingTimeout === 'undefined') {
|
||||
// Ensure at least the speaking bit is set.
|
||||
// As the object is by reference, it's only needed once per client re-connect.
|
||||
if (userStat.speaking === 0) {
|
||||
userStat.speaking = 1;
|
||||
userStat.speaking = Speaking.FLAGS.SPEAKING;
|
||||
}
|
||||
this.connection.onSpeaking({ user_id: userStat.userID, ssrc: ssrc, speaking: userStat.speaking });
|
||||
speakingTimeout = this.receiver.connection.client.setTimeout(() => {
|
||||
|
|
@ -106,15 +126,17 @@ class PacketHandler extends EventEmitter {
|
|||
speakingTimeout.refresh();
|
||||
}
|
||||
|
||||
let stream = this.streams.get(userStat.userID);
|
||||
if (!stream) return;
|
||||
stream = stream.stream;
|
||||
const opusPacket = this.parseBuffer(buffer);
|
||||
if (opusPacket instanceof Error) {
|
||||
this.emit('error', opusPacket);
|
||||
return;
|
||||
if (streamInfo) {
|
||||
const { stream } = streamInfo;
|
||||
if (!opusPacket) {
|
||||
opusPacket = this.parseBuffer(buffer);
|
||||
if (opusPacket instanceof Error) {
|
||||
this.emit('error', opusPacket);
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream.push(opusPacket);
|
||||
}
|
||||
stream.push(opusPacket);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,6 @@ class Silence extends Readable {
|
|||
}
|
||||
}
|
||||
|
||||
Silence.SILENCE_FRAME = SILENCE_FRAME;
|
||||
|
||||
module.exports = Silence;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class WebSocketManager extends EventEmitter {
|
|||
|
||||
/**
|
||||
* The current status of this WebSocketManager
|
||||
* @type {number}
|
||||
* @type {Status}
|
||||
*/
|
||||
this.status = Status.IDLE;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const { Status, Events } = require('../../../util/Constants');
|
||||
|
||||
module.exports = (client, { d: data }, shard) => {
|
||||
let user = client.users.cache.get(data.user.id);
|
||||
if (!user && data.user.username) user = client.users.add(data.user);
|
||||
if (user && data.user && data.user.username) {
|
||||
if (!user.equals(data.user)) client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const member = guild.members.cache.get(data.user.id);
|
||||
if (member) {
|
||||
const old = member._update(data);
|
||||
if (shard.status === Status.READY) {
|
||||
/**
|
||||
* Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
|
||||
* Also emitted when the user's details (e.g. username) change.
|
||||
* @event Client#guildMemberUpdate
|
||||
* @param {GuildMember} oldMember The member before the update
|
||||
* @param {GuildMember} newMember The member after the update
|
||||
*/
|
||||
client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = (client, packet, shard) => {
|
||||
client.actions.GuildMemberUpdate.handle(packet.d, shard);
|
||||
};
|
||||
|
|
|
|||
5
src/client/websocket/handlers/INTERACTION_CREATE.js
Normal file
5
src/client/websocket/handlers/INTERACTION_CREATE.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = (client, packet) => {
|
||||
client.actions.InteractionCreate.handle(packet.d);
|
||||
};
|
||||
|
|
@ -21,6 +21,7 @@ const Messages = {
|
|||
DISALLOWED_INTENTS: 'Privileged intent provided is not enabled or whitelisted.',
|
||||
SHARDING_NO_SHARDS: 'No shards have been spawned.',
|
||||
SHARDING_IN_PROCESS: 'Shards are still being spawned.',
|
||||
SHARDING_SHARD_NOT_FOUND: id => `Shard ${id} could not be found.`,
|
||||
SHARDING_ALREADY_SPAWNED: count => `Already spawned ${count} shards.`,
|
||||
SHARDING_PROCESS_EXISTS: id => `Shard ${id} already has an active process.`,
|
||||
SHARDING_WORKER_EXISTS: id => `Shard ${id} already has an active worker.`,
|
||||
|
|
@ -28,6 +29,8 @@ const Messages = {
|
|||
SHARDING_READY_DISCONNECTED: id => `Shard ${id}'s Client disconnected before becoming ready.`,
|
||||
SHARDING_READY_DIED: id => `Shard ${id}'s process exited before its Client became ready.`,
|
||||
SHARDING_NO_CHILD_EXISTS: id => `Shard ${id} has no active process or worker.`,
|
||||
SHARDING_SHARD_MISCALCULATION: (shard, guild, count) =>
|
||||
`Calculated invalid shard ${shard} for guild ${guild} with ${count} shards.`,
|
||||
|
||||
COLOR_RANGE: 'Color must be within the range 0 - 16777215 (0xFFFFFF).',
|
||||
COLOR_CONVERT: 'Unable to convert color to a number.',
|
||||
|
|
@ -68,7 +71,7 @@ const Messages = {
|
|||
IMAGE_SIZE: size => `Invalid image size: ${size}`,
|
||||
|
||||
MESSAGE_BULK_DELETE_TYPE: 'The messages must be an Array, Collection, or number.',
|
||||
MESSAGE_NONCE_TYPE: 'Message nonce must fit in an unsigned 64-bit integer.',
|
||||
MESSAGE_NONCE_TYPE: 'Message nonce must be an integer or a string.',
|
||||
|
||||
TYPING_COUNT: 'Count must be at least 1',
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ module.exports = {
|
|||
// "Root" classes (starting points)
|
||||
BaseClient: require('./client/BaseClient'),
|
||||
Client: require('./client/Client'),
|
||||
InteractionClient: require('./client/InteractionClient'),
|
||||
Shard: require('./sharding/Shard'),
|
||||
ShardClientUtil: require('./sharding/ShardClientUtil'),
|
||||
ShardingManager: require('./sharding/ShardingManager'),
|
||||
|
|
@ -33,6 +34,7 @@ module.exports = {
|
|||
version: require('../package.json').version,
|
||||
|
||||
// Managers
|
||||
BaseGuildEmojiManager: require('./managers/BaseGuildEmojiManager'),
|
||||
ChannelManager: require('./managers/ChannelManager'),
|
||||
GuildChannelManager: require('./managers/GuildChannelManager'),
|
||||
GuildEmojiManager: require('./managers/GuildEmojiManager'),
|
||||
|
|
@ -57,6 +59,7 @@ module.exports = {
|
|||
|
||||
// Structures
|
||||
Application: require('./structures/interfaces/Application'),
|
||||
ApplicationCommand: require('./structures/ApplicationCommand'),
|
||||
Base: require('./structures/Base'),
|
||||
Activity: require('./structures/Presence').Activity,
|
||||
APIMessage: require('./structures/APIMessage'),
|
||||
|
|
@ -77,7 +80,9 @@ module.exports = {
|
|||
GuildEmoji: require('./structures/GuildEmoji'),
|
||||
GuildMember: require('./structures/GuildMember'),
|
||||
GuildPreview: require('./structures/GuildPreview'),
|
||||
GuildTemplate: require('./structures/GuildTemplate'),
|
||||
Integration: require('./structures/Integration'),
|
||||
Interaction: require('./structures/Interaction'),
|
||||
Invite: require('./structures/Invite'),
|
||||
Message: require('./structures/Message'),
|
||||
MessageAttachment: require('./structures/MessageAttachment'),
|
||||
|
|
|
|||
80
src/managers/BaseGuildEmojiManager.js
Normal file
80
src/managers/BaseGuildEmojiManager.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
'use strict';
|
||||
|
||||
const BaseManager = require('./BaseManager');
|
||||
const GuildEmoji = require('../structures/GuildEmoji');
|
||||
const ReactionEmoji = require('../structures/ReactionEmoji');
|
||||
const { parseEmoji } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Holds methods to resolve GuildEmojis and stores their cache.
|
||||
* @extends {BaseManager}
|
||||
*/
|
||||
class BaseGuildEmojiManager extends BaseManager {
|
||||
constructor(client, iterable) {
|
||||
super(client, iterable, GuildEmoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* The cache of GuildEmojis
|
||||
* @type {Collection<Snowflake, GuildEmoji>}
|
||||
* @name BaseGuildEmojiManager#cache
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved into a GuildEmoji object. This can be:
|
||||
* * A custom emoji ID
|
||||
* * A GuildEmoji object
|
||||
* * A ReactionEmoji object
|
||||
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an Emoji object.
|
||||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify
|
||||
* @returns {?GuildEmoji}
|
||||
*/
|
||||
resolve(emoji) {
|
||||
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
|
||||
return super.resolve(emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an Emoji ID string.
|
||||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify
|
||||
* @returns {?Snowflake}
|
||||
*/
|
||||
resolveID(emoji) {
|
||||
if (emoji instanceof ReactionEmoji) return emoji.id;
|
||||
return super.resolveID(emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an emoji identifier. This can be:
|
||||
* * The unicode representation of an emoji
|
||||
* * The `<a:name:id>`, `<:name:id>`, `a:name:id` or `name:id` emoji identifier string of an emoji
|
||||
* * An EmojiResolvable
|
||||
* @typedef {string|EmojiResolvable} EmojiIdentifierResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an emoji identifier.
|
||||
* @param {EmojiIdentifierResolvable} emoji The emoji resolvable to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveIdentifier(emoji) {
|
||||
const emojiResolvable = this.resolve(emoji);
|
||||
if (emojiResolvable) return emojiResolvable.identifier;
|
||||
if (emoji instanceof ReactionEmoji) return emoji.identifier;
|
||||
if (typeof emoji === 'string') {
|
||||
const res = parseEmoji(emoji);
|
||||
if (res && res.name.length) {
|
||||
emoji = `${res.animated ? 'a:' : ''}${res.name}${res.id ? `:${res.id}` : ''}`;
|
||||
}
|
||||
if (!emoji.includes('%')) return encodeURIComponent(emoji);
|
||||
return emoji;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseGuildEmojiManager;
|
||||
|
|
@ -1,20 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
const BaseManager = require('./BaseManager');
|
||||
const BaseGuildEmojiManager = require('./BaseGuildEmojiManager');
|
||||
const { TypeError } = require('../errors');
|
||||
const GuildEmoji = require('../structures/GuildEmoji');
|
||||
const ReactionEmoji = require('../structures/ReactionEmoji');
|
||||
const Collection = require('../util/Collection');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const { parseEmoji } = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Manages API methods for GuildEmojis and stores their cache.
|
||||
* @extends {BaseManager}
|
||||
* @extends {BaseGuildEmojiManager}
|
||||
*/
|
||||
class GuildEmojiManager extends BaseManager {
|
||||
class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
constructor(guild, iterable) {
|
||||
super(guild.client, iterable, GuildEmoji);
|
||||
super(guild.client, iterable);
|
||||
|
||||
/**
|
||||
* The guild this manager belongs to
|
||||
* @type {Guild}
|
||||
|
|
@ -22,12 +20,6 @@ class GuildEmojiManager extends BaseManager {
|
|||
this.guild = guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* The cache of GuildEmojis
|
||||
* @type {Collection<Snowflake, GuildEmoji>}
|
||||
* @name GuildEmojiManager#cache
|
||||
*/
|
||||
|
||||
add(data, cache) {
|
||||
return super.add(data, cache, { extras: [this.guild] });
|
||||
}
|
||||
|
|
@ -74,62 +66,6 @@ class GuildEmojiManager extends BaseManager {
|
|||
.emojis.post({ data, reason })
|
||||
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved into an GuildEmoji object. This can be:
|
||||
* * A custom emoji ID
|
||||
* * A GuildEmoji object
|
||||
* * A ReactionEmoji object
|
||||
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an Emoji object.
|
||||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify
|
||||
* @returns {?GuildEmoji}
|
||||
*/
|
||||
resolve(emoji) {
|
||||
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id);
|
||||
return super.resolve(emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an Emoji ID string.
|
||||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify
|
||||
* @returns {?Snowflake}
|
||||
*/
|
||||
resolveID(emoji) {
|
||||
if (emoji instanceof ReactionEmoji) return emoji.id;
|
||||
return super.resolveID(emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an emoji identifier. This can be:
|
||||
* * The unicode representation of an emoji
|
||||
* * The `<a:name:id>`, `<:name:id>`, `:name:id` or `a:name:id` emoji identifier string of an emoji
|
||||
* * An EmojiResolvable
|
||||
* @typedef {string|EmojiResolvable} EmojiIdentifierResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an EmojiResolvable to an emoji identifier.
|
||||
* @param {EmojiIdentifierResolvable} emoji The emoji resolvable to resolve
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveIdentifier(emoji) {
|
||||
const emojiResolvable = this.resolve(emoji);
|
||||
if (emojiResolvable) return emojiResolvable.identifier;
|
||||
if (emoji instanceof ReactionEmoji) return emoji.identifier;
|
||||
if (typeof emoji === 'string') {
|
||||
const res = parseEmoji(emoji);
|
||||
if (res && res.name.length) {
|
||||
emoji = `${res.animated ? 'a:' : ''}${res.name}${res.id ? `:${res.id}` : ''}`;
|
||||
}
|
||||
if (!emoji.includes('%')) return encodeURIComponent(emoji);
|
||||
else return emoji;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildEmojiManager;
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ class GuildMemberManager extends BaseManager {
|
|||
* .catch(console.error);
|
||||
*/
|
||||
ban(user, options = { days: 0 }) {
|
||||
if (typeof options !== 'object') return Promise.reject(new TypeError('INVALID_TYPE', 'options', 'object', true));
|
||||
if (options.days) options.delete_message_days = options.days;
|
||||
const id = this.client.users.resolveID(user);
|
||||
if (!id) return Promise.reject(new Error('BAN_RESOLVE_ID', true));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const BaseManager = require('./BaseManager');
|
||||
const Role = require('../structures/Role');
|
||||
const Collection = require('../util/Collection');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const { resolveColor } = require('../util/Util');
|
||||
|
||||
|
|
@ -31,10 +32,10 @@ class RoleManager extends BaseManager {
|
|||
|
||||
/**
|
||||
* Obtains one or more roles from Discord, or the role cache if they're already available.
|
||||
* @param {Snowflake} [id] ID or IDs of the role(s)
|
||||
* @param {boolean} [cache=true] Whether to cache the new roles objects if it weren't already
|
||||
* @param {Snowflake} [id] ID of the role to fetch
|
||||
* @param {boolean} [cache=true] Whether to cache the new role object(s) if they weren't already
|
||||
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
||||
* @returns {Promise<Role|RoleManager>}
|
||||
* @returns {Promise<?Role|Collection<Snowflake, Role>>}
|
||||
* @example
|
||||
* // Fetch all roles from the guild
|
||||
* message.guild.roles.fetch()
|
||||
|
|
@ -53,9 +54,10 @@ class RoleManager extends BaseManager {
|
|||
}
|
||||
|
||||
// We cannot fetch a single role, as of this commit's date, Discord API throws with 405
|
||||
const roles = await this.client.api.guilds(this.guild.id).roles.get();
|
||||
for (const role of roles) this.add(role, cache);
|
||||
return id ? this.cache.get(id) || null : this;
|
||||
const data = await this.client.api.guilds(this.guild.id).roles.get();
|
||||
const roles = new Collection();
|
||||
for (const role of data) roles.set(role.id, this.add(role, cache));
|
||||
return id ? roles.get(id) || null : roles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Shard extends EventEmitter {
|
|||
* @type {Function}
|
||||
* @private
|
||||
*/
|
||||
this._exitListener = this._handleExit.bind(this);
|
||||
this._exitListener = this._handleExit.bind(this, undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -334,18 +334,20 @@ class Shard extends EventEmitter {
|
|||
|
||||
// Shard is requesting a property fetch
|
||||
if (message._sFetchProp) {
|
||||
this.manager.fetchClientValues(message._sFetchProp).then(
|
||||
results => this.send({ _sFetchProp: message._sFetchProp, _result: results }),
|
||||
err => this.send({ _sFetchProp: message._sFetchProp, _error: Util.makePlainError(err) }),
|
||||
const resp = { _sFetchProp: message._sFetchProp, _sFetchPropShard: message._sFetchPropShard };
|
||||
this.manager.fetchClientValues(message._sFetchProp, message._sFetchPropShard).then(
|
||||
results => this.send({ ...resp, _result: results }),
|
||||
err => this.send({ ...resp, _error: Util.makePlainError(err) }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shard is requesting an eval broadcast
|
||||
if (message._sEval) {
|
||||
this.manager.broadcastEval(message._sEval).then(
|
||||
results => this.send({ _sEval: message._sEval, _result: results }),
|
||||
err => this.send({ _sEval: message._sEval, _error: Util.makePlainError(err) }),
|
||||
const resp = { _sEval: message._sEval, _sEvalShard: message._sEvalShard };
|
||||
this.manager.broadcastEval(message._sEval, message._sEvalShard).then(
|
||||
results => this.send({ ...resp, _result: results }),
|
||||
err => this.send({ ...resp, _error: Util.makePlainError(err) }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,28 +96,29 @@ class ShardClientUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetches a client property value of each shard.
|
||||
* Fetches a client property value of each shard, or a given shard.
|
||||
* @param {string} prop Name of the client property to get, using periods for nesting
|
||||
* @returns {Promise<Array<*>>}
|
||||
* @param {number} [shard] Shard to fetch property from, all if undefined
|
||||
* @returns {Promise<*>|Promise<Array<*>>}
|
||||
* @example
|
||||
* client.shard.fetchClientValues('guilds.cache.size')
|
||||
* .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
|
||||
* .catch(console.error);
|
||||
* @see {@link ShardingManager#fetchClientValues}
|
||||
*/
|
||||
fetchClientValues(prop) {
|
||||
fetchClientValues(prop, shard) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const parent = this.parentPort || process;
|
||||
|
||||
const listener = message => {
|
||||
if (!message || message._sFetchProp !== prop) return;
|
||||
if (!message || message._sFetchProp !== prop || message._sFetchPropShard !== shard) return;
|
||||
parent.removeListener('message', listener);
|
||||
if (!message._error) resolve(message._result);
|
||||
else reject(Util.makeError(message._error));
|
||||
};
|
||||
parent.on('message', listener);
|
||||
|
||||
this.send({ _sFetchProp: prop }).catch(err => {
|
||||
this.send({ _sFetchProp: prop, _sFetchPropShard: shard }).catch(err => {
|
||||
parent.removeListener('message', listener);
|
||||
reject(err);
|
||||
});
|
||||
|
|
@ -125,29 +126,30 @@ class ShardClientUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Evaluates a script or function on all shards, in the context of the {@link Client}s.
|
||||
* Evaluates a script or function on all shards, or a given shard, in the context of the {@link Client}s.
|
||||
* @param {string|Function} script JavaScript to run on each shard
|
||||
* @returns {Promise<Array<*>>} Results of the script execution
|
||||
* @param {number} [shard] Shard to run script on, all if undefined
|
||||
* @returns {Promise<*>|Promise<Array<*>>} Results of the script execution
|
||||
* @example
|
||||
* client.shard.broadcastEval('this.guilds.cache.size')
|
||||
* .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
|
||||
* .catch(console.error);
|
||||
* @see {@link ShardingManager#broadcastEval}
|
||||
*/
|
||||
broadcastEval(script) {
|
||||
broadcastEval(script, shard) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const parent = this.parentPort || process;
|
||||
script = typeof script === 'function' ? `(${script})(this)` : script;
|
||||
|
||||
const listener = message => {
|
||||
if (!message || message._sEval !== script) return;
|
||||
if (!message || message._sEval !== script || message._sEvalShard !== shard) return;
|
||||
parent.removeListener('message', listener);
|
||||
if (!message._error) resolve(message._result);
|
||||
else reject(Util.makeError(message._error));
|
||||
};
|
||||
parent.on('message', listener);
|
||||
|
||||
this.send({ _sEval: script }).catch(err => {
|
||||
this.send({ _sEval: script, _sEvalShard: shard }).catch(err => {
|
||||
parent.removeListener('message', listener);
|
||||
reject(err);
|
||||
});
|
||||
|
|
@ -224,6 +226,18 @@ class ShardClientUtil {
|
|||
}
|
||||
return this._singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shard ID for a given guild ID.
|
||||
* @param {Snowflake} guildID Snowflake guild ID to get shard ID for
|
||||
* @param {number} shardCount Number of shards
|
||||
* @returns {number}
|
||||
*/
|
||||
static shardIDForGuildID(guildID, shardCount) {
|
||||
const shard = Number(BigInt(guildID) >> 22n) % shardCount;
|
||||
if (shard < 0) throw new Error('SHARDING_SHARD_MISCALCULATION', shard, guildID, shardCount);
|
||||
return shard;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ShardClientUtil;
|
||||
|
|
|
|||
|
|
@ -222,30 +222,48 @@ class ShardingManager extends EventEmitter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Evaluates a script on all shards, in the context of the {@link Client}s.
|
||||
* Evaluates a script on all shards, or a given shard, in the context of the {@link Client}s.
|
||||
* @param {string} script JavaScript to run on each shard
|
||||
* @returns {Promise<Array<*>>} Results of the script execution
|
||||
* @param {number} [shard] Shard to run on, all if undefined
|
||||
* @returns {Promise<*>|Promise<Array<*>>} Results of the script execution
|
||||
*/
|
||||
broadcastEval(script) {
|
||||
const promises = [];
|
||||
for (const shard of this.shards.values()) promises.push(shard.eval(script));
|
||||
return Promise.all(promises);
|
||||
broadcastEval(script, shard) {
|
||||
return this._performOnShards('eval', [script], shard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a client property value of each shard.
|
||||
* Fetches a client property value of each shard, or a given shard.
|
||||
* @param {string} prop Name of the client property to get, using periods for nesting
|
||||
* @returns {Promise<Array<*>>}
|
||||
* @param {number} [shard] Shard to fetch property from, all if undefined
|
||||
* @returns {Promise<*>|Promise<Array<*>>}
|
||||
* @example
|
||||
* manager.fetchClientValues('guilds.cache.size')
|
||||
* .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchClientValues(prop) {
|
||||
fetchClientValues(prop, shard) {
|
||||
return this._performOnShards('fetchClientValue', [prop], shard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a method with given arguments on all shards, or a given shard.
|
||||
* @param {string} method Method name to run on each shard
|
||||
* @param {Array<*>} args Arguments to pass through to the method call
|
||||
* @param {number} [shard] Shard to run on, all if undefined
|
||||
* @returns {Promise<*>|Promise<Array<*>>} Results of the method execution
|
||||
* @private
|
||||
*/
|
||||
_performOnShards(method, args, shard) {
|
||||
if (this.shards.size === 0) return Promise.reject(new Error('SHARDING_NO_SHARDS'));
|
||||
if (this.shards.size !== this.shardList.length) return Promise.reject(new Error('SHARDING_IN_PROCESS'));
|
||||
|
||||
if (typeof shard === 'number') {
|
||||
if (this.shards.has(shard)) return this.shards.get(shard)[method](...args);
|
||||
return Promise.reject(new Error('SHARDING_SHARD_NOT_FOUND', shard));
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
for (const shard of this.shards.values()) promises.push(shard.fetchClientValue(prop));
|
||||
for (const sh of this.shards.values()) promises.push(sh[method](...args));
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,13 +74,21 @@ class APIMessage {
|
|||
return this.target instanceof Message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the target is an interaction
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
get isInteraction() {
|
||||
const Interaction = require('./Interaction');
|
||||
return this.target instanceof Interaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the content of this message.
|
||||
* @returns {?(string|string[])}
|
||||
*/
|
||||
makeContent() {
|
||||
const GuildMember = require('./GuildMember');
|
||||
|
||||
let content;
|
||||
if (this.options.content === null) {
|
||||
content = '';
|
||||
|
|
@ -110,25 +118,14 @@ class APIMessage {
|
|||
const isCode = typeof this.options.code !== 'undefined' && this.options.code !== false;
|
||||
const splitOptions = isSplit ? { ...this.options.split } : undefined;
|
||||
|
||||
let mentionPart = '';
|
||||
if (this.options.reply && !this.isUser && this.target.type !== 'dm') {
|
||||
const id = this.target.client.users.resolveID(this.options.reply);
|
||||
mentionPart = `<@${this.options.reply instanceof GuildMember && this.options.reply.nickname ? '!' : ''}${id}>, `;
|
||||
if (isSplit) {
|
||||
splitOptions.prepend = `${mentionPart}${splitOptions.prepend || ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (content || mentionPart) {
|
||||
if (content) {
|
||||
if (isCode) {
|
||||
const codeName = typeof this.options.code === 'string' ? this.options.code : '';
|
||||
content = `${mentionPart}\`\`\`${codeName}\n${Util.cleanCodeBlockContent(content)}\n\`\`\``;
|
||||
content = `\`\`\`${codeName}\n${Util.cleanCodeBlockContent(content)}\n\`\`\``;
|
||||
if (isSplit) {
|
||||
splitOptions.prepend = `${splitOptions.prepend || ''}\`\`\`${codeName}\n`;
|
||||
splitOptions.append = `\n\`\`\`${splitOptions.append || ''}`;
|
||||
}
|
||||
} else if (mentionPart) {
|
||||
content = `${mentionPart}${content}`;
|
||||
}
|
||||
|
||||
if (isSplit) {
|
||||
|
|
@ -151,8 +148,11 @@ class APIMessage {
|
|||
|
||||
let nonce;
|
||||
if (typeof this.options.nonce !== 'undefined') {
|
||||
nonce = parseInt(this.options.nonce);
|
||||
if (isNaN(nonce) || nonce < 0) throw new RangeError('MESSAGE_NONCE_TYPE');
|
||||
nonce = this.options.nonce;
|
||||
// eslint-disable-next-line max-len
|
||||
if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') {
|
||||
throw new RangeError('MESSAGE_NONCE_TYPE');
|
||||
}
|
||||
}
|
||||
|
||||
const embedLikes = [];
|
||||
|
|
@ -176,25 +176,28 @@ class APIMessage {
|
|||
if (this.isMessage) {
|
||||
// eslint-disable-next-line eqeqeq
|
||||
flags = this.options.flags != null ? new MessageFlags(this.options.flags).bitfield : this.target.flags.bitfield;
|
||||
} else if (this.isInteraction) {
|
||||
flags = this.options.ephemeral ? MessageFlags.EPHEMERAL : undefined;
|
||||
}
|
||||
|
||||
let allowedMentions =
|
||||
typeof this.options.allowedMentions === 'undefined'
|
||||
? this.target.client.options.allowedMentions
|
||||
: this.options.allowedMentions;
|
||||
if (this.options.reply) {
|
||||
const id = this.target.client.users.resolveID(this.options.reply);
|
||||
if (allowedMentions) {
|
||||
// Clone the object as not to alter the ClientOptions object
|
||||
allowedMentions = Util.cloneObject(allowedMentions);
|
||||
const parsed = allowedMentions.parse && allowedMentions.parse.includes('users');
|
||||
// Check if the mention won't be parsed, and isn't supplied in `users`
|
||||
if (!parsed && !(allowedMentions.users && allowedMentions.users.includes(id))) {
|
||||
if (!allowedMentions.users) allowedMentions.users = [];
|
||||
allowedMentions.users.push(id);
|
||||
}
|
||||
} else {
|
||||
allowedMentions = { users: [id] };
|
||||
|
||||
if (allowedMentions) {
|
||||
allowedMentions = Util.cloneObject(allowedMentions);
|
||||
allowedMentions.replied_user = allowedMentions.repliedUser;
|
||||
delete allowedMentions.repliedUser;
|
||||
}
|
||||
|
||||
let message_reference;
|
||||
if (typeof this.options.replyTo !== 'undefined') {
|
||||
const message_id = this.isMessage
|
||||
? this.target.channel.messages.resolveID(this.options.replyTo)
|
||||
: this.target.messages.resolveID(this.options.replyTo);
|
||||
if (message_id) {
|
||||
message_reference = { message_id };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,8 +209,10 @@ class APIMessage {
|
|||
embeds,
|
||||
username,
|
||||
avatar_url: avatarURL,
|
||||
allowed_mentions: typeof content === 'undefined' ? undefined : allowedMentions,
|
||||
allowed_mentions:
|
||||
typeof content === 'undefined' && typeof message_reference === 'undefined' ? undefined : allowedMentions,
|
||||
flags,
|
||||
message_reference,
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
102
src/structures/ApplicationCommand.js
Normal file
102
src/structures/ApplicationCommand.js
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
'use strict';
|
||||
|
||||
const Base = require('./Base');
|
||||
const { ApplicationCommandOptionType } = require('../util/Constants');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
|
||||
/**
|
||||
* Represents an application command, see {@link InteractionClient}.
|
||||
* @extends {Base}
|
||||
*/
|
||||
class ApplicationCommand extends Base {
|
||||
constructor(client, data, guildID) {
|
||||
super(client);
|
||||
|
||||
/**
|
||||
* The ID of the guild this command is part of, if any.
|
||||
* @type {Snowflake?}
|
||||
* @readonly
|
||||
*/
|
||||
this.guildID = guildID || null;
|
||||
|
||||
this._patch(data);
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
/**
|
||||
* The ID of this command.
|
||||
* @type {Snowflake}
|
||||
* @readonly
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* The ID of the application which owns this command.
|
||||
* @type {Snowflake}
|
||||
* @readonly
|
||||
*/
|
||||
this.appplicationID = data.application_id;
|
||||
|
||||
/**
|
||||
* The name of this command.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The description of this command.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.description = data.description;
|
||||
|
||||
/**
|
||||
* The options of this command.
|
||||
* @type {Object[]}
|
||||
* @readonly
|
||||
*/
|
||||
this.options = data.options?.map(function m(o) {
|
||||
return {
|
||||
type: ApplicationCommandOptionType[o.type],
|
||||
name: o.name,
|
||||
description: o.description,
|
||||
default: o.default,
|
||||
required: o.required,
|
||||
choices: o.choices,
|
||||
options: o.options ? o.options.map(m) : undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp the command was created at.
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return Snowflake.deconstruct(this.id).timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the command was created at.
|
||||
* @type {Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this command.
|
||||
*/
|
||||
async delete() {
|
||||
let path = this.client.api.applications('@me');
|
||||
if (this.guildID) {
|
||||
path = path.guilds(this.guildID);
|
||||
}
|
||||
await path.commands(this.id).delete();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApplicationCommand;
|
||||
|
|
@ -17,7 +17,7 @@ class BaseGuildEmoji extends Emoji {
|
|||
*/
|
||||
this.guild = guild;
|
||||
|
||||
this.requireColons = null;
|
||||
this.requiresColons = null;
|
||||
this.managed = null;
|
||||
this.available = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class Emoji extends Base {
|
|||
* @example
|
||||
* // Send a custom emoji from a guild:
|
||||
* const emoji = guild.emojis.cache.first();
|
||||
* msg.reply(`Hello! ${emoji}`);
|
||||
* msg.channel.send(`Hello! ${emoji}`);
|
||||
* @example
|
||||
* // Send the emoji used in a reaction to the channel the reaction is part of
|
||||
* reaction.message.channel.send(`The emoji used was: ${reaction.emoji}`);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const { deprecate } = require('util');
|
|||
const Base = require('./Base');
|
||||
const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const GuildPreview = require('./GuildPreview');
|
||||
const GuildTemplate = require('./GuildTemplate');
|
||||
const Integration = require('./Integration');
|
||||
const Invite = require('./Invite');
|
||||
const VoiceRegion = require('./VoiceRegion');
|
||||
|
|
@ -17,6 +18,7 @@ const RoleManager = require('../managers/RoleManager');
|
|||
const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const Collection = require('../util/Collection');
|
||||
const {
|
||||
browser,
|
||||
ChannelTypes,
|
||||
DefaultMessageNotifications,
|
||||
PartialTypes,
|
||||
|
|
@ -635,18 +637,6 @@ class Guild extends Base {
|
|||
return this.voiceStates.cache.get(this.client.user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GuildMember form of a User object, if the user is present in the guild.
|
||||
* @param {UserResolvable} user The user that you want to obtain the GuildMember of
|
||||
* @returns {?GuildMember}
|
||||
* @example
|
||||
* // Get the guild member of a user
|
||||
* const member = guild.member(message.author);
|
||||
*/
|
||||
member(user) {
|
||||
return this.members.resolve(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches this guild.
|
||||
* @returns {Promise<Guild>}
|
||||
|
|
@ -733,6 +723,20 @@ class Guild extends Base {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of templates from this guild.
|
||||
* Resolves with a collection mapping templates by their codes.
|
||||
* @returns {Promise<Collection<string, GuildTemplate>>}
|
||||
*/
|
||||
fetchTemplates() {
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.templates.get()
|
||||
.then(templates =>
|
||||
templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data for creating an integration.
|
||||
* @typedef {Object} IntegrationData
|
||||
|
|
@ -753,6 +757,19 @@ class Guild extends Base {
|
|||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a template for the guild.
|
||||
* @param {string} name The name for the template
|
||||
* @param {string} [description] The description for the template
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
createTemplate(name, description) {
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.templates.post({ data: { name, description } })
|
||||
.then(data => new GuildTemplate(this.client, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of invites to this guild.
|
||||
* Resolves with a collection mapping invites by their codes.
|
||||
|
|
@ -965,29 +982,25 @@ class Guild extends Base {
|
|||
* @param {boolean} [options.deaf] Whether the member should be deafened (requires `DEAFEN_MEMBERS`)
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
addMember(user, options) {
|
||||
async addMember(user, options) {
|
||||
user = this.client.users.resolveID(user);
|
||||
if (!user) return Promise.reject(new TypeError('INVALID_TYPE', 'user', 'UserResolvable'));
|
||||
if (this.members.cache.has(user)) return Promise.resolve(this.members.cache.get(user));
|
||||
if (!user) throw new TypeError('INVALID_TYPE', 'user', 'UserResolvable');
|
||||
if (this.members.cache.has(user)) return this.members.cache.get(user);
|
||||
options.access_token = options.accessToken;
|
||||
if (options.roles) {
|
||||
const roles = [];
|
||||
for (let role of options.roles instanceof Collection ? options.roles.values() : options.roles) {
|
||||
role = this.roles.resolve(role);
|
||||
if (!role) {
|
||||
return Promise.reject(
|
||||
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
|
||||
);
|
||||
throw new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
roles.push(role.id);
|
||||
}
|
||||
options.roles = roles;
|
||||
}
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.members(user)
|
||||
.put({ data: options })
|
||||
.then(data => this.members.add(data));
|
||||
const data = await this.client.api.guilds(this.id).members(user).put({ data: options });
|
||||
// Data is an empty buffer if the member is already part of the guild.
|
||||
return data instanceof (browser ? ArrayBuffer : Buffer) ? this.members.fetch(user) : this.members.add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1419,6 +1432,23 @@ class Guild extends Base {
|
|||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commands associated with this guild.
|
||||
* @returns {ApplicationCommand[]} A list of commands.
|
||||
*/
|
||||
getCommands() {
|
||||
return this.client.interactionClient.getCommands(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a command. See {@link InteractionClient}.
|
||||
* @param {Object} command The command description.
|
||||
* @returns {ApplicationCommand} The created command.
|
||||
*/
|
||||
createCommand(command) {
|
||||
return this.client.interactionClient.createCommand(command, this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves the guild.
|
||||
* @returns {Promise<Guild>}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ class GuildChannel extends Channel {
|
|||
* @type {Guild}
|
||||
*/
|
||||
this.guild = guild;
|
||||
|
||||
this.parentID = null;
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
|
|
|
|||
225
src/structures/GuildTemplate.js
Normal file
225
src/structures/GuildTemplate.js
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
'use strict';
|
||||
|
||||
const Base = require('./Base');
|
||||
const { Events } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
|
||||
/**
|
||||
* Represents the template for a guild.
|
||||
* @extends {Base}
|
||||
*/
|
||||
class GuildTemplate extends Base {
|
||||
/**
|
||||
* @param {Client} client The instantiating client
|
||||
* @param {Object} data The raw data for the template
|
||||
*/
|
||||
constructor(client, data) {
|
||||
super(client);
|
||||
this._patch(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds or updates the template with the provided data.
|
||||
* @param {Object} data The raw data for the template
|
||||
* @returns {GuildTemplate}
|
||||
* @private
|
||||
*/
|
||||
_patch(data) {
|
||||
/**
|
||||
* The unique code of this template
|
||||
* @type {string}
|
||||
*/
|
||||
this.code = data.code;
|
||||
|
||||
/**
|
||||
* The name of this template
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The description of this template
|
||||
* @type {?string}
|
||||
*/
|
||||
this.description = data.description;
|
||||
|
||||
/**
|
||||
* The amount of times this template has been used
|
||||
* @type {number}
|
||||
*/
|
||||
this.usageCount = data.usage_count;
|
||||
|
||||
/**
|
||||
* The ID of the user that created this template
|
||||
* @type {Snowflake}
|
||||
*/
|
||||
this.creatorID = data.creator_id;
|
||||
|
||||
/**
|
||||
* The user that created this template
|
||||
* @type {User}
|
||||
*/
|
||||
this.creator = this.client.users.add(data.creator);
|
||||
|
||||
/**
|
||||
* The time of when this template was created at
|
||||
* @type {Date}
|
||||
*/
|
||||
this.createdAt = new Date(data.created_at);
|
||||
|
||||
/**
|
||||
* The time of when this template was last synced to the guild
|
||||
* @type {Date}
|
||||
*/
|
||||
this.updatedAt = new Date(data.updated_at);
|
||||
|
||||
/**
|
||||
* The ID of the guild that this template belongs to
|
||||
* @type {Snowflake}
|
||||
*/
|
||||
this.guildID = data.source_guild_id;
|
||||
|
||||
/**
|
||||
* The data of the guild that this template would create
|
||||
* @type {Object}
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#guild-resource}
|
||||
*/
|
||||
this.serializedGuild = data.serialized_source_guild;
|
||||
|
||||
/**
|
||||
* Whether this template has unsynced changes
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.unSynced = 'is_dirty' in data ? Boolean(data.is_dirty) : null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a guild based from this template.
|
||||
* <warn>This is only available to bots in fewer than 10 guilds.</warn>
|
||||
* @param {string} name The name of the guild
|
||||
* @param {BufferResolvable|Base64Resolvable} [icon] The icon for the guild
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
async createGuild(name, icon) {
|
||||
const { client } = this;
|
||||
const data = await client.api.guilds.templates(this.code).post({
|
||||
data: {
|
||||
name,
|
||||
icon: await DataResolver.resolveImage(icon),
|
||||
},
|
||||
});
|
||||
// eslint-disable-next-line consistent-return
|
||||
return new Promise(resolve => {
|
||||
const createdGuild = client.guilds.cache.get(data.id);
|
||||
if (createdGuild) return resolve(createdGuild);
|
||||
|
||||
const resolveGuild = guild => {
|
||||
client.off(Events.GUILD_CREATE, handleGuild);
|
||||
client.decrementMaxListeners();
|
||||
resolve(guild);
|
||||
};
|
||||
|
||||
const handleGuild = guild => {
|
||||
if (guild.id === data.id) {
|
||||
client.clearTimeout(timeout);
|
||||
resolveGuild(guild);
|
||||
}
|
||||
};
|
||||
|
||||
client.incrementMaxListeners();
|
||||
client.on(Events.GUILD_CREATE, handleGuild);
|
||||
|
||||
const timeout = client.setTimeout(() => resolveGuild(client.guilds.add(data)), 10000);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the metadata on this template.
|
||||
* @param {Object} options Options for the template
|
||||
* @param {string} [options.name] The name of this template
|
||||
* @param {string} [options.description] The description of this template
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
edit({ name, description } = {}) {
|
||||
return this.client.api
|
||||
.guilds(this.guildID)
|
||||
.templates(this.code)
|
||||
.patch({ data: { name, description } })
|
||||
.then(data => this._patch(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this template.
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
delete() {
|
||||
return this.client.api
|
||||
.guilds(this.guildID)
|
||||
.templates(this.code)
|
||||
.delete()
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs this template to the current state of the guild.
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
sync() {
|
||||
return this.client.api
|
||||
.guilds(this.guildID)
|
||||
.templates(this.code)
|
||||
.put()
|
||||
.then(data => this._patch(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp of when this template was created at
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return this.createdAt.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp of when this template was last synced to the guild
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get updatedTimestamp() {
|
||||
return this.updatedAt.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* The guild that this template belongs to
|
||||
* @type {?Guild}
|
||||
* @readonly
|
||||
*/
|
||||
get guild() {
|
||||
return this.client.guilds.cache.get(this.guildID) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL of this template
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
get url() {
|
||||
return `${this.client.options.http.template}/${this.code}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* When concatenated with a string, this automatically returns the templates's code instead of the template object.
|
||||
* @returns {string}
|
||||
* @example
|
||||
* // Logs: Template: FKvmczH2HyUf
|
||||
* console.log(`Template: ${guildTemplate}!`);
|
||||
*/
|
||||
toString() {
|
||||
return this.code;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildTemplate;
|
||||
133
src/structures/Interaction.js
Normal file
133
src/structures/Interaction.js
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
'use strict';
|
||||
|
||||
const APIMessage = require('./APIMessage');
|
||||
const Base = require('./Base');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
|
||||
/**
|
||||
* Represents an interaction, see {@link InteractionClient}.
|
||||
* @extends {Base}
|
||||
*/
|
||||
class Interaction extends Base {
|
||||
constructor(client, data, syncHandle) {
|
||||
super(client);
|
||||
this.syncHandle = syncHandle;
|
||||
this._patch(data);
|
||||
}
|
||||
|
||||
_patch(data) {
|
||||
/**
|
||||
* The ID of this interaction.
|
||||
* @type {Snowflake}
|
||||
* @readonly
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* The token of this interaction.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.token = data.token;
|
||||
|
||||
/**
|
||||
* The ID of the invoked command.
|
||||
* @type {Snowflake}
|
||||
* @readonly
|
||||
*/
|
||||
this.commandID = data.data.id;
|
||||
|
||||
/**
|
||||
* The name of the invoked command.
|
||||
* @type {string}
|
||||
* @readonly
|
||||
*/
|
||||
this.commandName = data.data.name;
|
||||
|
||||
/**
|
||||
* The options passed to the command.
|
||||
* @type {Object}
|
||||
* @readonly
|
||||
*/
|
||||
this.options = data.data.options;
|
||||
|
||||
/**
|
||||
* The channel this interaction was sent in.
|
||||
* @type {?Channel}
|
||||
* @readonly
|
||||
*/
|
||||
this.channel = this.client.channels?.cache.get(data.channel_id) || null;
|
||||
|
||||
/**
|
||||
* The guild this interaction was sent in, if any.
|
||||
* @type {?Guild}
|
||||
* @readonly
|
||||
*/
|
||||
this.guild = data.guild_id ? this.client.guilds?.cache.get(data.guild_id) : null;
|
||||
|
||||
/**
|
||||
* If this interaction was sent in a guild, the member which sent it.
|
||||
* @type {?Member}
|
||||
* @readonly
|
||||
*/
|
||||
this.member = data.member ? this.guild?.members.add(data.member, false) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp the interaction was created at.
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return Snowflake.deconstruct(this.id).timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the interaction was created at.
|
||||
* @type {Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acknowledge this interaction without content.
|
||||
*/
|
||||
async acknowledge() {
|
||||
await this.syncHandle.acknowledge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reply to this interaction.
|
||||
* @param {(StringResolvable | APIMessage)?} content The content for the message.
|
||||
* @param {(MessageOptions | MessageAdditions)?} options The options to provide.
|
||||
*/
|
||||
async reply(content, options) {
|
||||
let apiMessage;
|
||||
|
||||
if (content instanceof APIMessage) {
|
||||
apiMessage = content.resolveData();
|
||||
} else {
|
||||
apiMessage = APIMessage.create(this, content, options).resolveData();
|
||||
if (Array.isArray(apiMessage.data.content)) {
|
||||
throw new Error('Message is too long');
|
||||
}
|
||||
}
|
||||
|
||||
const resolved = await apiMessage.resolveFiles();
|
||||
|
||||
if (!this.syncHandle.reply(resolved)) {
|
||||
const clientID =
|
||||
this.client.interactionClient.clientID || (await this.client.api.oauth2.applications('@me').get()).id;
|
||||
|
||||
await this.client.api.webhooks(clientID, this.token).post({
|
||||
auth: false,
|
||||
data: resolved.data,
|
||||
files: resolved.files,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Interaction;
|
||||
|
|
@ -205,11 +205,11 @@ class Message extends Base {
|
|||
this.flags = new MessageFlags(data.flags).freeze();
|
||||
|
||||
/**
|
||||
* Reference data sent in a crossposted message.
|
||||
* Reference data sent in a crossposted message or inline reply.
|
||||
* @typedef {Object} MessageReference
|
||||
* @property {string} channelID ID of the channel the message was crossposted from
|
||||
* @property {?string} guildID ID of the guild the message was crossposted from
|
||||
* @property {?string} messageID ID of the message that was crossposted
|
||||
* @property {string} channelID ID of the channel the message was referenced
|
||||
* @property {?string} guildID ID of the guild the message was referenced
|
||||
* @property {?string} messageID ID of the message that was referenced
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -223,6 +223,10 @@ class Message extends Base {
|
|||
messageID: data.message_reference.message_id,
|
||||
}
|
||||
: null;
|
||||
|
||||
if (data.referenced_message) {
|
||||
this.channel.messages.add(data.referenced_message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -284,7 +288,7 @@ class Message extends Base {
|
|||
* @readonly
|
||||
*/
|
||||
get member() {
|
||||
return this.guild ? this.guild.member(this.author) || null : null;
|
||||
return this.guild ? this.guild.members.resolve(this.author) || null : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -425,6 +429,35 @@ class Message extends Base {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Message this crosspost/reply/pin-add references, if cached
|
||||
* @type {?Message}
|
||||
* @readonly
|
||||
*/
|
||||
get referencedMessage() {
|
||||
if (!this.reference) return null;
|
||||
const referenceChannel = this.client.channels.resolve(this.reference.channelID);
|
||||
if (!referenceChannel) return null;
|
||||
return referenceChannel.messages.resolve(this.reference.messageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the message is crosspostable by the client user
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
get crosspostable() {
|
||||
return (
|
||||
this.channel.type === 'news' &&
|
||||
!this.flags.has(MessageFlags.FLAGS.CROSSPOSTED) &&
|
||||
this.type === 'DEFAULT' &&
|
||||
this.channel.viewable &&
|
||||
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.SEND_MESSAGES) &&
|
||||
(this.author.id === this.client.user.id ||
|
||||
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options that can be passed into editMessage.
|
||||
* @typedef {Object} MessageEditOptions
|
||||
|
|
@ -571,21 +604,19 @@ class Message extends Base {
|
|||
}
|
||||
|
||||
/**
|
||||
* Replies to the message.
|
||||
* Send an inline reply to this message.
|
||||
* @param {StringResolvable|APIMessage} [content=''] The content for the message
|
||||
* @param {MessageOptions|MessageAdditions} [options={}] The options to provide
|
||||
* @param {MessageOptions|MessageAdditions} [options] The additional options to provide
|
||||
* @param {MessageResolvable} [options.replyTo=this] The message to reply to
|
||||
* @returns {Promise<Message|Message[]>}
|
||||
* @example
|
||||
* // Reply to a message
|
||||
* message.reply('Hey, I\'m a reply!')
|
||||
* .then(() => console.log(`Sent a reply to ${message.author.username}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
reply(content, options) {
|
||||
return this.channel.send(
|
||||
content instanceof APIMessage
|
||||
? content
|
||||
: APIMessage.transformOptions(content, options, { reply: this.member || this.author }),
|
||||
: APIMessage.transformOptions(content, options, {
|
||||
replyTo: this,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class MessageMentions {
|
|||
if (!this.guild) return null;
|
||||
this._members = new Collection();
|
||||
this.users.forEach(user => {
|
||||
const member = this.guild.member(user);
|
||||
const member = this.guild.members.resolve(user);
|
||||
if (member) this._members.set(member.user.id, member);
|
||||
});
|
||||
return this._members;
|
||||
|
|
|
|||
|
|
@ -28,12 +28,6 @@ class MessageReaction {
|
|||
*/
|
||||
this.message = message;
|
||||
|
||||
/**
|
||||
* Whether the client has given this reaction
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.me = data.me;
|
||||
|
||||
/**
|
||||
* A manager of the users that have given this reaction
|
||||
* @type {ReactionUserManager}
|
||||
|
|
@ -54,6 +48,12 @@ class MessageReaction {
|
|||
*/
|
||||
this.count = data.count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the client has given this reaction
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.me = data.me;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class Role extends Base {
|
|||
*/
|
||||
get editable() {
|
||||
if (this.managed) return false;
|
||||
const clientMember = this.guild.member(this.client.user);
|
||||
const clientMember = this.guild.members.resolve(this.client.user);
|
||||
if (!clientMember.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) return false;
|
||||
return clientMember.roles.highest.comparePositionTo(this) > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ class User extends Base {
|
|||
this.id = data.id;
|
||||
|
||||
this.system = null;
|
||||
this.locale = null;
|
||||
this.flags = null;
|
||||
|
||||
this._patch(data);
|
||||
|
|
@ -45,11 +44,13 @@ class User extends Base {
|
|||
this.username = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the user is a bot
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.bot = Boolean(data.bot);
|
||||
if ('bot' in data || typeof this.bot !== 'boolean') {
|
||||
/**
|
||||
* Whether or not the user is a bot
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.bot = Boolean(data.bot);
|
||||
}
|
||||
|
||||
if ('discriminator' in data) {
|
||||
/**
|
||||
|
|
@ -79,14 +80,6 @@ class User extends Base {
|
|||
this.system = Boolean(data.system);
|
||||
}
|
||||
|
||||
if ('locale' in data) {
|
||||
/**
|
||||
* The locale of the user's client (ISO 639-1)
|
||||
* @type {?string}
|
||||
*/
|
||||
this.locale = data.locale;
|
||||
}
|
||||
|
||||
if ('public_flags' in data) {
|
||||
/**
|
||||
* The flags for this user
|
||||
|
|
@ -285,7 +278,7 @@ class User extends Base {
|
|||
|
||||
/**
|
||||
* Fetches this user's flags.
|
||||
* @param {boolean} [force=false] Whether to skip the cache check and request the AP
|
||||
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
||||
* @returns {Promise<UserFlags>}
|
||||
*/
|
||||
async fetchFlags(force = false) {
|
||||
|
|
@ -297,7 +290,7 @@ class User extends Base {
|
|||
|
||||
/**
|
||||
* Fetches this user.
|
||||
* @param {boolean} [force=false] Whether to skip the cache check and request the AP
|
||||
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
||||
* @returns {Promise<User>}
|
||||
*/
|
||||
fetch(force = false) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const { TypeError } = require('../../errors');
|
||||
const Collection = require('../../util/Collection');
|
||||
const Util = require('../../util/Util');
|
||||
|
||||
|
|
@ -74,6 +75,10 @@ class Collector extends EventEmitter {
|
|||
*/
|
||||
this._idletimeout = null;
|
||||
|
||||
if (typeof filter !== 'function') {
|
||||
throw new TypeError('INVALID_TYPE', 'filter', 'function');
|
||||
}
|
||||
|
||||
this.handleCollect = this.handleCollect.bind(this);
|
||||
this.handleDispose = this.handleDispose.bind(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class TextBasedChannel {
|
|||
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
|
||||
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
||||
* it exceeds the character limit. If an object is provided, these are the options for splitting the message
|
||||
* @property {UserResolvable} [reply] User to reply to (prefixes the message with a mention, except in DMs)
|
||||
* @property {MessageResolvable} [replyTo] The message to reply to (must be in the same channel)
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
@ -74,6 +74,7 @@ class TextBasedChannel {
|
|||
* @property {MessageMentionTypes[]} [parse] Types of mentions to be parsed
|
||||
* @property {Snowflake[]} [users] Snowflakes of Users to be parsed as mentions
|
||||
* @property {Snowflake[]} [roles] Snowflakes of Roles to be parsed as mentions
|
||||
* @property {boolean} [repliedUser] Whether the author of the Message being replied to should be pinged
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -77,16 +77,18 @@ exports.DefaultOptions = {
|
|||
/**
|
||||
* HTTP options
|
||||
* @typedef {Object} HTTPOptions
|
||||
* @property {number} [version=7] API version to use
|
||||
* @property {number} [version=8] API version to use
|
||||
* @property {string} [api='https://discord.com/api'] Base url of the API
|
||||
* @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN
|
||||
* @property {string} [invite='https://discord.gg'] Base url of invites
|
||||
* @property {string} [template='https://discord.new'] Base url of templates
|
||||
*/
|
||||
http: {
|
||||
version: 7,
|
||||
version: 8,
|
||||
api: 'https://discord.com/api',
|
||||
cdn: 'https://cdn.discordapp.com',
|
||||
invite: 'https://discord.gg',
|
||||
template: 'https://discord.new',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -280,6 +282,7 @@ exports.Events = {
|
|||
SHARD_READY: 'shardReady',
|
||||
SHARD_RESUME: 'shardResume',
|
||||
INVALIDATED: 'invalidated',
|
||||
INTERACTION_CREATE: 'interactionCreate',
|
||||
RAW: 'raw',
|
||||
};
|
||||
|
||||
|
|
@ -343,6 +346,7 @@ exports.PartialTypes = keyMirror(['USER', 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE',
|
|||
* * VOICE_STATE_UPDATE
|
||||
* * VOICE_SERVER_UPDATE
|
||||
* * WEBHOOKS_UPDATE
|
||||
* * INTERACTION_CREATE
|
||||
* @typedef {string} WSEventType
|
||||
*/
|
||||
exports.WSEvents = keyMirror([
|
||||
|
|
@ -382,6 +386,7 @@ exports.WSEvents = keyMirror([
|
|||
'VOICE_STATE_UPDATE',
|
||||
'VOICE_SERVER_UPDATE',
|
||||
'WEBHOOKS_UPDATE',
|
||||
'INTERACTION_CREATE',
|
||||
]);
|
||||
|
||||
/**
|
||||
|
|
@ -401,6 +406,7 @@ exports.WSEvents = keyMirror([
|
|||
* * CHANNEL_FOLLOW_ADD
|
||||
* * GUILD_DISCOVERY_DISQUALIFIED
|
||||
* * GUILD_DISCOVERY_REQUALIFIED
|
||||
* * REPLY
|
||||
* @typedef {string} MessageType
|
||||
*/
|
||||
exports.MessageTypes = [
|
||||
|
|
@ -420,6 +426,10 @@ exports.MessageTypes = [
|
|||
null,
|
||||
'GUILD_DISCOVERY_DISQUALIFIED',
|
||||
'GUILD_DISCOVERY_REQUALIFIED',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'REPLY',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -519,17 +529,27 @@ exports.VerificationLevels = ['NONE', 'LOW', 'MEDIUM', 'HIGH', 'VERY_HIGH'];
|
|||
* * UNKNOWN_USER
|
||||
* * UNKNOWN_EMOJI
|
||||
* * UNKNOWN_WEBHOOK
|
||||
* * UNKNOWN_BAN
|
||||
* * UNKNOWN_GUILD_TEMPLATE
|
||||
* * BOT_PROHIBITED_ENDPOINT
|
||||
* * BOT_ONLY_ENDPOINT
|
||||
* * CHANNEL_HIT_WRITE_RATELIMIT
|
||||
* * MAXIMUM_GUILDS
|
||||
* * MAXIMUM_FRIENDS
|
||||
* * MAXIMUM_PINS
|
||||
* * MAXIMUM_ROLES
|
||||
* * MAXIMUM_WEBHOOKS
|
||||
* * MAXIMUM_REACTIONS
|
||||
* * MAXIMUM_CHANNELS
|
||||
* * MAXIMUM_ATTACHMENTS
|
||||
* * MAXIMUM_INVITES
|
||||
* * GUILD_ALREADY_HAS_TEMPLATE
|
||||
* * UNAUTHORIZED
|
||||
* * ACCOUNT_VERIFICATION_REQUIRED
|
||||
* * REQUEST_ENTITY_TOO_LARGE
|
||||
* * FEATURE_TEMPORARILY_DISABLED
|
||||
* * USER_BANNED
|
||||
* * ALREADY_CROSSPOSTED
|
||||
* * MISSING_ACCESS
|
||||
* * INVALID_ACCOUNT_TYPE
|
||||
* * CANNOT_EXECUTE_ON_DM
|
||||
|
|
@ -554,6 +574,7 @@ exports.VerificationLevels = ['NONE', 'LOW', 'MEDIUM', 'HIGH', 'VERY_HIGH'];
|
|||
* * INVALID_FORM_BODY
|
||||
* * INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT
|
||||
* * INVALID_API_VERSION
|
||||
* * CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL
|
||||
* * REACTION_BLOCKED
|
||||
* * RESOURCE_OVERLOADED
|
||||
* @typedef {string} APIError
|
||||
|
|
@ -574,17 +595,27 @@ exports.APIErrors = {
|
|||
UNKNOWN_USER: 10013,
|
||||
UNKNOWN_EMOJI: 10014,
|
||||
UNKNOWN_WEBHOOK: 10015,
|
||||
UNKNOWN_BAN: 10026,
|
||||
UNKNOWN_GUILD_TEMPLATE: 10057,
|
||||
BOT_PROHIBITED_ENDPOINT: 20001,
|
||||
BOT_ONLY_ENDPOINT: 20002,
|
||||
CHANNEL_HIT_WRITE_RATELIMIT: 20028,
|
||||
MAXIMUM_GUILDS: 30001,
|
||||
MAXIMUM_FRIENDS: 30002,
|
||||
MAXIMUM_PINS: 30003,
|
||||
MAXIMUM_ROLES: 30005,
|
||||
MAXIMUM_WEBHOOKS: 30007,
|
||||
MAXIMUM_REACTIONS: 30010,
|
||||
MAXIMUM_CHANNELS: 30013,
|
||||
MAXIMUM_ATTACHMENTS: 30015,
|
||||
MAXIMUM_INVITES: 30016,
|
||||
GUILD_ALREADY_HAS_TEMPLATE: 30031,
|
||||
UNAUTHORIZED: 40001,
|
||||
ACCOUNT_VERIFICATION_REQUIRED: 40002,
|
||||
REQUEST_ENTITY_TOO_LARGE: 40005,
|
||||
FEATURE_TEMPORARILY_DISABLED: 40006,
|
||||
USER_BANNED: 40007,
|
||||
ALREADY_CROSSPOSTED: 40033,
|
||||
MISSING_ACCESS: 50001,
|
||||
INVALID_ACCOUNT_TYPE: 50002,
|
||||
CANNOT_EXECUTE_ON_DM: 50003,
|
||||
|
|
@ -609,6 +640,7 @@ exports.APIErrors = {
|
|||
INVALID_FORM_BODY: 50035,
|
||||
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036,
|
||||
INVALID_API_VERSION: 50041,
|
||||
CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL: 50074,
|
||||
REACTION_BLOCKED: 90001,
|
||||
RESOURCE_OVERLOADED: 130000,
|
||||
};
|
||||
|
|
@ -647,6 +679,33 @@ exports.WebhookTypes = [
|
|||
'Channel Follower',
|
||||
];
|
||||
|
||||
exports.ApplicationCommandOptionType = {
|
||||
SUB_COMMAND: 1,
|
||||
SUB_COMMAND_GROUP: 2,
|
||||
STRING: 3,
|
||||
INTEGER: 4,
|
||||
BOOLEAN: 5,
|
||||
USER: 6,
|
||||
CHANNEL: 7,
|
||||
ROLE: 8,
|
||||
};
|
||||
Object.entries(exports.ApplicationCommandOptionType).forEach(([k, v]) => {
|
||||
exports.ApplicationCommandOptionType[v] = k;
|
||||
});
|
||||
|
||||
exports.InteractionType = {
|
||||
PING: 1,
|
||||
APPLICATION_COMMAND: 2,
|
||||
};
|
||||
|
||||
exports.InteractionResponseType = {
|
||||
PONG: 1,
|
||||
ACKNOWLEDGE: 2,
|
||||
CHANNEL_MESSAGE: 3,
|
||||
CHANNEL_MESSAGE_WITH_SOURCE: 4,
|
||||
ACKNOWLEDGE_WITH_SOURCE: 5,
|
||||
};
|
||||
|
||||
function keyMirror(arr) {
|
||||
let tmp = Object.create(null);
|
||||
for (const value of arr) tmp[value] = value;
|
||||
|
|
|
|||
|
|
@ -24,16 +24,40 @@ class DataResolver {
|
|||
* @typedef {string} InviteResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an template code. This can be:
|
||||
* * A template code
|
||||
* * A template URL
|
||||
* @typedef {string} GuildTemplateResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves the string to a code based on the passed regex.
|
||||
* @param {string} data The string to resolve
|
||||
* @param {RegExp} regex The RegExp used to extract the code
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveCode(data, regex) {
|
||||
const match = regex.exec(data);
|
||||
return match ? match[1] || data : data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves InviteResolvable to an invite code.
|
||||
* @param {InviteResolvable} data The invite resolvable to resolve
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveInviteCode(data) {
|
||||
const inviteRegex = /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/i;
|
||||
const match = inviteRegex.exec(data);
|
||||
if (match && match[1]) return match[1];
|
||||
return data;
|
||||
return this.resolveCode(data, /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves GuildTemplateResolvable to a template code.
|
||||
* @param {GuildTemplateResolvable} data The template resolvable to resolve
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveGuildTemplateCode(data) {
|
||||
return this.resolveCode(data, /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class MessageFlags extends BitField {}
|
|||
* * `SUPPRESS_EMBEDS`
|
||||
* * `SOURCE_MESSAGE_DELETED`
|
||||
* * `URGENT`
|
||||
* * `EPHEMERAL`
|
||||
* @type {Object}
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#message-object-message-flags}
|
||||
*/
|
||||
|
|
@ -31,6 +32,7 @@ MessageFlags.FLAGS = {
|
|||
SUPPRESS_EMBEDS: 1 << 2,
|
||||
SOURCE_MESSAGE_DELETED: 1 << 3,
|
||||
URGENT: 1 << 4,
|
||||
EPHEMERAL: 1 << 6,
|
||||
};
|
||||
|
||||
module.exports = MessageFlags;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ class SnowflakeUtil {
|
|||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discord's epoch value (2015-01-01T00:00:00.000Z).
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
static get EPOCH() {
|
||||
return EPOCH;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SnowflakeUtil;
|
||||
|
|
|
|||
|
|
@ -5,16 +5,19 @@ const libs = {
|
|||
open: sodium.api.crypto_secretbox_open_easy,
|
||||
close: sodium.api.crypto_secretbox_easy,
|
||||
random: n => sodium.randombytes_buf(n),
|
||||
verify: sodium.api.crypto_sign_verify_detached,
|
||||
}),
|
||||
'libsodium-wrappers': sodium => ({
|
||||
open: sodium.crypto_secretbox_open_easy,
|
||||
close: sodium.crypto_secretbox_easy,
|
||||
random: n => sodium.randombytes_buf(n),
|
||||
verify: sodium.crypto_sign_verify_detached,
|
||||
}),
|
||||
tweetnacl: tweetnacl => ({
|
||||
open: tweetnacl.secretbox.open,
|
||||
close: tweetnacl.secretbox,
|
||||
random: n => tweetnacl.randomBytes(n),
|
||||
verify: (s, d, p) => tweetnacl.sign.detached.verify(d, s, p),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
@ -36,9 +36,9 @@ client.on('message', message => {
|
|||
// Clean content and log each character
|
||||
console.log(Util.cleanContent(args.join(' '), message).split(''));
|
||||
|
||||
if (command === 'test1') message.reply(tests[0]);
|
||||
else if (command === 'test2') message.reply(tests[1]);
|
||||
else if (command === 'test3') message.reply(tests[2]);
|
||||
if (command === 'test1') message.channel.send(tests[0]);
|
||||
else if (command === 'test2') message.channel.send(tests[1]);
|
||||
else if (command === 'test3') message.channel.send(tests[2]);
|
||||
});
|
||||
|
||||
client.login(token).catch(console.error);
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ client.on('message', message => {
|
|||
|
||||
if (message.content.startsWith('kick')) {
|
||||
message.guild
|
||||
.member(message.mentions.users.first())
|
||||
.members
|
||||
.resolve(message.mentions.users.first())
|
||||
.kick()
|
||||
.then(member => {
|
||||
console.log(member);
|
||||
|
|
@ -134,7 +135,7 @@ client.on('message', message => {
|
|||
}
|
||||
message.channel.send('last one...').then(m => {
|
||||
const diff = Date.now() - start;
|
||||
m.reply(`Each message took ${diff / 21}ms to send`);
|
||||
m.channel.send(`Each message took ${diff / 21}ms to send`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +206,7 @@ client.on('message', msg => {
|
|||
.join()
|
||||
.then(conn => {
|
||||
con = conn;
|
||||
msg.reply('done');
|
||||
msg.channel.send('done');
|
||||
const s = ytdl(song, { filter: 'audioonly' }, { passes: 3 });
|
||||
s.on('error', e => console.log(`e w stream 2 ${e}`));
|
||||
disp = conn.playStream(s);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ const tests = [
|
|||
|
||||
m => m.channel.send(fill('x'), { split: true }),
|
||||
m => m.channel.send(fill('1'), { code: 'js', split: true }),
|
||||
m => m.channel.send(fill('x'), { reply: m.author, code: 'js', split: true }),
|
||||
m => m.channel.send(fill('xyz '), { split: { char: ' ' } }),
|
||||
|
||||
m => m.channel.send('x', { embed: { description: 'a' } }),
|
||||
|
|
@ -99,7 +98,6 @@ const tests = [
|
|||
async m => m.channel.send({ files: [await read(fileA)] }),
|
||||
async m =>
|
||||
m.channel.send(fill('x'), {
|
||||
reply: m.author,
|
||||
code: 'js',
|
||||
split: true,
|
||||
embed: embed().setImage('attachment://zero.png'),
|
||||
|
|
@ -111,7 +109,6 @@ const tests = [
|
|||
m => m.channel.send({ files: [{ attachment: readStream(fileA) }] }),
|
||||
async m =>
|
||||
m.channel.send(fill('xyz '), {
|
||||
reply: m.author,
|
||||
code: 'js',
|
||||
split: { char: ' ', prepend: 'hello! ', append: '!!!' },
|
||||
embed: embed().setImage('attachment://zero.png'),
|
||||
|
|
|
|||
|
|
@ -31,16 +31,13 @@ const commands = {
|
|||
}
|
||||
message.channel.send(res, { code: 'js' });
|
||||
},
|
||||
ping: message => message.reply('pong'),
|
||||
ping: message => message.channel.send('pong'),
|
||||
};
|
||||
|
||||
client.on('message', message => {
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
|
||||
message.content = message.content
|
||||
.replace(prefix, '')
|
||||
.trim()
|
||||
.split(' ');
|
||||
message.content = message.content.replace(prefix, '').trim().split(' ');
|
||||
const command = message.content.shift();
|
||||
message.content = message.content.join(' ');
|
||||
|
||||
|
|
|
|||
|
|
@ -43,20 +43,15 @@ client.on('message', m => {
|
|||
conn.receiver.createStream(m.author, true).on('data', b => console.log(b.toString()));
|
||||
conn.player.on('error', (...e) => console.log('player', ...e));
|
||||
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
|
||||
m.reply('ok!');
|
||||
m.channel.send('ok!');
|
||||
conn.play(ytdl('https://www.youtube.com/watch?v=_XXOSf0s2nk', { filter: 'audioonly' }, { passes: 3 }));
|
||||
});
|
||||
} else {
|
||||
m.reply('Specify a voice channel!');
|
||||
m.channel.send('Specify a voice channel!');
|
||||
}
|
||||
} else if (m.content.startsWith('#eval') && m.author.id === '66564597481480192') {
|
||||
try {
|
||||
const com = eval(
|
||||
m.content
|
||||
.split(' ')
|
||||
.slice(1)
|
||||
.join(' '),
|
||||
);
|
||||
const com = eval(m.content.split(' ').slice(1).join(' '));
|
||||
m.channel.send(com, { code: true });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ const tests = [
|
|||
|
||||
(m, hook) => hook.send(fill('x'), { split: true }),
|
||||
(m, hook) => hook.send(fill('1'), { code: 'js', split: true }),
|
||||
(m, hook) => hook.send(fill('x'), { reply: m.author, code: 'js', split: true }),
|
||||
(m, hook) => hook.send(fill('xyz '), { split: { char: ' ' } }),
|
||||
|
||||
(m, hook) => hook.send({ embeds: [{ description: 'a' }] }),
|
||||
|
|
@ -96,7 +95,6 @@ const tests = [
|
|||
async (m, hook) => hook.send({ files: [await read(fileA)] }),
|
||||
async (m, hook) =>
|
||||
hook.send(fill('x'), {
|
||||
reply: m.author,
|
||||
code: 'js',
|
||||
split: true,
|
||||
embeds: [embed().setImage('attachment://zero.png')],
|
||||
|
|
@ -108,7 +106,6 @@ const tests = [
|
|||
(m, hook) => hook.send({ files: [{ attachment: readStream(fileA) }] }),
|
||||
async (m, hook) =>
|
||||
hook.send(fill('xyz '), {
|
||||
reply: m.author,
|
||||
code: 'js',
|
||||
split: { char: ' ', prepend: 'hello! ', append: '!!!' },
|
||||
embeds: [embed().setImage('attachment://zero.png')],
|
||||
|
|
|
|||
245
typings/index.d.ts
vendored
245
typings/index.d.ts
vendored
|
|
@ -199,7 +199,7 @@ declare module 'discord.js' {
|
|||
private _validateOptions(options?: ClientOptions): void;
|
||||
|
||||
public channels: ChannelManager;
|
||||
public readonly emojis: GuildEmojiManager;
|
||||
public readonly emojis: BaseGuildEmojiManager;
|
||||
public guilds: GuildManager;
|
||||
public readyAt: Date | null;
|
||||
public readonly readyTimestamp: number | null;
|
||||
|
|
@ -214,6 +214,7 @@ declare module 'discord.js' {
|
|||
public fetchApplication(): Promise<ClientApplication>;
|
||||
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
||||
public fetchInvite(invite: InviteResolvable): Promise<Invite>;
|
||||
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
||||
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
||||
public fetchWebhook(id: Snowflake, token?: string): Promise<Webhook>;
|
||||
public generateInvite(options?: InviteGenerationOptions | PermissionResolvable): Promise<string>;
|
||||
|
|
@ -482,59 +483,7 @@ declare module 'discord.js' {
|
|||
HELLO: 10;
|
||||
HEARTBEAT_ACK: 11;
|
||||
};
|
||||
APIErrors: {
|
||||
UNKNOWN_ACCOUNT: 10001;
|
||||
UNKNOWN_APPLICATION: 10002;
|
||||
UNKNOWN_CHANNEL: 10003;
|
||||
UNKNOWN_GUILD: 10004;
|
||||
UNKNOWN_INTEGRATION: 10005;
|
||||
UNKNOWN_INVITE: 10006;
|
||||
UNKNOWN_MEMBER: 10007;
|
||||
UNKNOWN_MESSAGE: 10008;
|
||||
UNKNOWN_OVERWRITE: 10009;
|
||||
UNKNOWN_PROVIDER: 10010;
|
||||
UNKNOWN_ROLE: 10011;
|
||||
UNKNOWN_TOKEN: 10012;
|
||||
UNKNOWN_USER: 10013;
|
||||
UNKNOWN_EMOJI: 10014;
|
||||
UNKNOWN_WEBHOOK: 10015;
|
||||
BOT_PROHIBITED_ENDPOINT: 20001;
|
||||
BOT_ONLY_ENDPOINT: 20002;
|
||||
MAXIMUM_GUILDS: 30001;
|
||||
MAXIMUM_FRIENDS: 30002;
|
||||
MAXIMUM_PINS: 30003;
|
||||
MAXIMUM_ROLES: 30005;
|
||||
MAXIMUM_REACTIONS: 30010;
|
||||
MAXIMUM_CHANNELS: 30013;
|
||||
MAXIMUM_INVITES: 30016;
|
||||
UNAUTHORIZED: 40001;
|
||||
USER_BANNED: 40007;
|
||||
MISSING_ACCESS: 50001;
|
||||
INVALID_ACCOUNT_TYPE: 50002;
|
||||
CANNOT_EXECUTE_ON_DM: 50003;
|
||||
EMBED_DISABLED: 50004;
|
||||
CANNOT_EDIT_MESSAGE_BY_OTHER: 50005;
|
||||
CANNOT_SEND_EMPTY_MESSAGE: 50006;
|
||||
CANNOT_MESSAGE_USER: 50007;
|
||||
CANNOT_SEND_MESSAGES_IN_VOICE_CHANNEL: 50008;
|
||||
CHANNEL_VERIFICATION_LEVEL_TOO_HIGH: 50009;
|
||||
OAUTH2_APPLICATION_BOT_ABSENT: 50010;
|
||||
MAXIMUM_OAUTH2_APPLICATIONS: 50011;
|
||||
INVALID_OAUTH_STATE: 50012;
|
||||
MISSING_PERMISSIONS: 50013;
|
||||
INVALID_AUTHENTICATION_TOKEN: 50014;
|
||||
NOTE_TOO_LONG: 50015;
|
||||
INVALID_BULK_DELETE_QUANTITY: 50016;
|
||||
CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL: 50019;
|
||||
CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: 50021;
|
||||
INVALID_OAUTH_TOKEN: 50025;
|
||||
BULK_DELETE_MESSAGE_TOO_OLD: 50034;
|
||||
INVALID_FORM_BODY: 50035;
|
||||
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036;
|
||||
INVALID_API_VERSION: 50041;
|
||||
REACTION_BLOCKED: 90001;
|
||||
RESOURCE_OVERLOADED: 130000;
|
||||
};
|
||||
APIErrors: APIErrors;
|
||||
VoiceStatus: {
|
||||
CONNECTED: 0;
|
||||
CONNECTING: 1;
|
||||
|
|
@ -576,10 +525,12 @@ declare module 'discord.js' {
|
|||
|
||||
export class DataResolver {
|
||||
public static resolveBase64(data: Base64Resolvable): string;
|
||||
public static resolveCode(data: string, regx: RegExp): string;
|
||||
public static resolveFile(resource: BufferResolvable | Stream): Promise<Buffer | Stream>;
|
||||
public static resolveFileAsBuffer(resource: BufferResolvable | Stream): Promise<Buffer>;
|
||||
public static resolveImage(resource: BufferResolvable | Base64Resolvable): Promise<string>;
|
||||
public static resolveInviteCode(data: InviteResolvable): string;
|
||||
public static resolveGuildTemplateCode(data: GuildTemplateResolvable): string;
|
||||
}
|
||||
|
||||
export class DiscordAPIError extends Error {
|
||||
|
|
@ -686,6 +637,7 @@ declare module 'discord.js' {
|
|||
public addMember(user: UserResolvable, options: AddGuildMemberOptions): Promise<GuildMember>;
|
||||
public bannerURL(options?: ImageURLOptions): string | null;
|
||||
public createIntegration(data: IntegrationData, reason?: string): Promise<Guild>;
|
||||
public createTemplate(name: string, description?: string): Promise<GuildTemplate>;
|
||||
public delete(): Promise<Guild>;
|
||||
public discoverySplashURL(options?: ImageURLOptions): string | null;
|
||||
public edit(data: GuildEditData, reason?: string): Promise<Guild>;
|
||||
|
|
@ -698,6 +650,7 @@ declare module 'discord.js' {
|
|||
public fetchIntegrations(options?: FetchIntegrationsOptions): Promise<Collection<string, Integration>>;
|
||||
public fetchInvites(): Promise<Collection<string, Invite>>;
|
||||
public fetchPreview(): Promise<GuildPreview>;
|
||||
public fetchTemplates(): Promise<Collection<GuildTemplate['code'], GuildTemplate>>;
|
||||
public fetchVanityCode(): Promise<string>;
|
||||
public fetchVanityData(): Promise<{ code: string; uses: number }>;
|
||||
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
||||
|
|
@ -705,7 +658,6 @@ declare module 'discord.js' {
|
|||
public fetchWidget(): Promise<GuildWidget>;
|
||||
public iconURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
|
||||
public leave(): Promise<Guild>;
|
||||
public member(user: UserResolvable): GuildMember | null;
|
||||
public setAFKChannel(afkChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||
public setAFKTimeout(afkTimeout: number, reason?: string): Promise<Guild>;
|
||||
public setBanner(banner: Base64Resolvable | null, reason?: string): Promise<Guild>;
|
||||
|
|
@ -904,6 +856,29 @@ declare module 'discord.js' {
|
|||
public toString(): string;
|
||||
}
|
||||
|
||||
export class GuildTemplate extends Base {
|
||||
constructor(client: Client, data: object);
|
||||
public readonly createdTimestamp: number;
|
||||
public readonly updatedTimestamp: number;
|
||||
public readonly url: string;
|
||||
public code: string;
|
||||
public name: string;
|
||||
public description: string | null;
|
||||
public usageCount: number;
|
||||
public creator: User;
|
||||
public creatorID: Snowflake;
|
||||
public createdAt: Date;
|
||||
public updatedAt: Date;
|
||||
public guild: Guild | null;
|
||||
public guildID: Snowflake;
|
||||
public serializedGuild: object;
|
||||
public unSynced: boolean | null;
|
||||
public createGuild(name: string, icon?: BufferResolvable | Base64Resolvable): Promise<Guild>;
|
||||
public delete(): Promise<GuildTemplate>;
|
||||
public edit(options?: { name?: string; description?: string }): Promise<GuildTemplate>;
|
||||
public sync(): Promise<GuildTemplate>;
|
||||
}
|
||||
|
||||
export class GuildPreviewEmoji extends BaseGuildEmoji {
|
||||
constructor(client: Client, data: object, guild: GuildPreview);
|
||||
public guild: GuildPreview;
|
||||
|
|
@ -1000,7 +975,7 @@ declare module 'discord.js' {
|
|||
public id: Snowflake;
|
||||
public readonly member: GuildMember | null;
|
||||
public mentions: MessageMentions;
|
||||
public nonce: string | null;
|
||||
public nonce: string | number | null;
|
||||
public readonly partial: false;
|
||||
public readonly pinnable: boolean;
|
||||
public pinned: boolean;
|
||||
|
|
@ -1012,6 +987,7 @@ declare module 'discord.js' {
|
|||
public webhookID: Snowflake | null;
|
||||
public flags: Readonly<MessageFlags>;
|
||||
public reference: MessageReference | null;
|
||||
public readonly referencedMessage: Message | null;
|
||||
public awaitReactions(
|
||||
filter: CollectorFilter,
|
||||
options?: AwaitReactionsOptions,
|
||||
|
|
@ -1165,6 +1141,7 @@ declare module 'discord.js' {
|
|||
constructor(client: Client, data: object, message: Message);
|
||||
private _emoji: GuildEmoji | ReactionEmoji;
|
||||
|
||||
public readonly client: Client;
|
||||
public count: number | null;
|
||||
public readonly emoji: GuildEmoji | ReactionEmoji;
|
||||
public me: boolean;
|
||||
|
|
@ -1375,12 +1352,16 @@ declare module 'discord.js' {
|
|||
public mode: ShardingManagerMode;
|
||||
public parentPort: any | null;
|
||||
public broadcastEval(script: string): Promise<any[]>;
|
||||
public broadcastEval(script: string, shard: number): Promise<any>;
|
||||
public broadcastEval<T>(fn: (client: Client) => T): Promise<T[]>;
|
||||
public broadcastEval<T>(fn: (client: Client) => T, shard: number): Promise<T>;
|
||||
public fetchClientValues(prop: string): Promise<any[]>;
|
||||
public fetchClientValues(prop: string, shard: number): Promise<any>;
|
||||
public respawnAll(shardDelay?: number, respawnDelay?: number, spawnTimeout?: number): Promise<void>;
|
||||
public send(message: any): Promise<void>;
|
||||
|
||||
public static singleton(client: Client, mode: ShardingManagerMode): ShardClientUtil;
|
||||
public static shardIDForGuildID(guildID: Snowflake, shardCount: number): number;
|
||||
}
|
||||
|
||||
export class ShardingManager extends EventEmitter {
|
||||
|
|
@ -1396,6 +1377,8 @@ declare module 'discord.js' {
|
|||
execArgv?: string[];
|
||||
},
|
||||
);
|
||||
private _performOnShards(method: string, args: any[]): Promise<any[]>;
|
||||
private _performOnShards(method: string, args: any[], shard: number): Promise<any>;
|
||||
|
||||
public file: string;
|
||||
public respawn: boolean;
|
||||
|
|
@ -1405,8 +1388,10 @@ declare module 'discord.js' {
|
|||
public totalShards: number | 'auto';
|
||||
public broadcast(message: any): Promise<Shard[]>;
|
||||
public broadcastEval(script: string): Promise<any[]>;
|
||||
public broadcastEval(script: string, shard: number): Promise<any>;
|
||||
public createShard(id: number): Shard;
|
||||
public fetchClientValues(prop: string): Promise<any[]>;
|
||||
public fetchClientValues(prop: string, shard: number): Promise<any>;
|
||||
public respawnAll(
|
||||
shardDelay?: number,
|
||||
respawnDelay?: number,
|
||||
|
|
@ -1422,6 +1407,7 @@ declare module 'discord.js' {
|
|||
export class SnowflakeUtil {
|
||||
public static deconstruct(snowflake: Snowflake): DeconstructedSnowflake;
|
||||
public static generate(timestamp?: number | Date): Snowflake;
|
||||
public static readonly EPOCH: number;
|
||||
}
|
||||
|
||||
export class Speaking extends BitField<SpeakingString> {
|
||||
|
|
@ -1543,7 +1529,6 @@ declare module 'discord.js' {
|
|||
public flags: Readonly<UserFlags> | null;
|
||||
public id: Snowflake;
|
||||
public lastMessageID: Snowflake | null;
|
||||
public locale: string | null;
|
||||
public readonly partial: false;
|
||||
public readonly presence: Presence;
|
||||
public system: boolean | null;
|
||||
|
|
@ -1886,11 +1871,6 @@ declare module 'discord.js' {
|
|||
|
||||
//#region Managers
|
||||
|
||||
export class ChannelManager extends BaseManager<Snowflake, Channel, ChannelResolvable> {
|
||||
constructor(client: Client, iterable: Iterable<any>);
|
||||
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Channel>;
|
||||
}
|
||||
|
||||
export abstract class BaseManager<K, Holds, R> {
|
||||
constructor(client: Client, iterable: Iterable<any>, holds: Constructable<Holds>, cacheType: Collection<K, Holds>);
|
||||
public holds: Constructable<Holds>;
|
||||
|
|
@ -1903,6 +1883,16 @@ declare module 'discord.js' {
|
|||
public valueOf(): Collection<K, Holds>;
|
||||
}
|
||||
|
||||
export class BaseGuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
|
||||
constructor(client: Client, iterable?: Iterable<any>);
|
||||
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
|
||||
}
|
||||
|
||||
export class ChannelManager extends BaseManager<Snowflake, Channel, ChannelResolvable> {
|
||||
constructor(client: Client, iterable: Iterable<any>);
|
||||
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Channel>;
|
||||
}
|
||||
|
||||
export class GuildChannelManager extends BaseManager<Snowflake, GuildChannel, GuildChannelResolvable> {
|
||||
constructor(guild: Guild, iterable?: Iterable<any>);
|
||||
public guild: Guild;
|
||||
|
|
@ -1915,7 +1905,7 @@ declare module 'discord.js' {
|
|||
): Promise<TextChannel | VoiceChannel | CategoryChannel>;
|
||||
}
|
||||
|
||||
export class GuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
|
||||
export class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
constructor(guild: Guild, iterable?: Iterable<any>);
|
||||
public guild: Guild;
|
||||
public create(
|
||||
|
|
@ -1923,7 +1913,6 @@ declare module 'discord.js' {
|
|||
name: string,
|
||||
options?: GuildEmojiCreateOptions,
|
||||
): Promise<GuildEmoji>;
|
||||
public resolveIdentifier(emoji: EmojiIdentifierResolvable): string | null;
|
||||
}
|
||||
|
||||
export class GuildEmojiRoleManager {
|
||||
|
|
@ -2027,7 +2016,7 @@ declare module 'discord.js' {
|
|||
|
||||
public create(options?: { data?: RoleData; reason?: string }): Promise<Role>;
|
||||
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Role | null>;
|
||||
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<this>;
|
||||
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, Role>>;
|
||||
}
|
||||
|
||||
export class UserManager extends BaseManager<Snowflake, User, UserResolvable> {
|
||||
|
|
@ -2135,51 +2124,70 @@ declare module 'discord.js' {
|
|||
deaf?: boolean;
|
||||
}
|
||||
|
||||
interface APIError {
|
||||
UNKNOWN_ACCOUNT: number;
|
||||
UNKNOWN_APPLICATION: number;
|
||||
UNKNOWN_CHANNEL: number;
|
||||
UNKNOWN_GUILD: number;
|
||||
UNKNOWN_INTEGRATION: number;
|
||||
UNKNOWN_INVITE: number;
|
||||
UNKNOWN_MEMBER: number;
|
||||
UNKNOWN_MESSAGE: number;
|
||||
UNKNOWN_OVERWRITE: number;
|
||||
UNKNOWN_PROVIDER: number;
|
||||
UNKNOWN_ROLE: number;
|
||||
UNKNOWN_TOKEN: number;
|
||||
UNKNOWN_USER: number;
|
||||
UNKNOWN_EMOJI: number;
|
||||
UNKNOWN_WEBHOOK: number;
|
||||
BOT_PROHIBITED_ENDPOINT: number;
|
||||
BOT_ONLY_ENDPOINT: number;
|
||||
MAXIMUM_GUILDS: number;
|
||||
MAXIMUM_FRIENDS: number;
|
||||
MAXIMUM_PINS: number;
|
||||
MAXIMUM_ROLES: number;
|
||||
MAXIMUM_REACTIONS: number;
|
||||
UNAUTHORIZED: number;
|
||||
MISSING_ACCESS: number;
|
||||
INVALID_ACCOUNT_TYPE: number;
|
||||
CANNOT_EXECUTE_ON_DM: number;
|
||||
EMBED_DISABLED: number;
|
||||
CANNOT_EDIT_MESSAGE_BY_OTHER: number;
|
||||
CANNOT_SEND_EMPTY_MESSAGE: number;
|
||||
CANNOT_MESSAGE_USER: number;
|
||||
CANNOT_SEND_MESSAGES_IN_VOICE_CHANNEL: number;
|
||||
CHANNEL_VERIFICATION_LEVEL_TOO_HIGH: number;
|
||||
OAUTH2_APPLICATION_BOT_ABSENT: number;
|
||||
MAXIMUM_OAUTH2_APPLICATIONS: number;
|
||||
INVALID_OAUTH_STATE: number;
|
||||
MISSING_PERMISSIONS: number;
|
||||
INVALID_AUTHENTICATION_TOKEN: number;
|
||||
NOTE_TOO_LONG: number;
|
||||
INVALID_BULK_DELETE_QUANTITY: number;
|
||||
CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL: number;
|
||||
CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: number;
|
||||
BULK_DELETE_MESSAGE_TOO_OLD: number;
|
||||
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: number;
|
||||
REACTION_BLOCKED: number;
|
||||
interface APIErrors {
|
||||
UNKNOWN_ACCOUNT: 10001;
|
||||
UNKNOWN_APPLICATION: 10002;
|
||||
UNKNOWN_CHANNEL: 10003;
|
||||
UNKNOWN_GUILD: 10004;
|
||||
UNKNOWN_INTEGRATION: 10005;
|
||||
UNKNOWN_INVITE: 10006;
|
||||
UNKNOWN_MEMBER: 10007;
|
||||
UNKNOWN_MESSAGE: 10008;
|
||||
UNKNOWN_OVERWRITE: 10009;
|
||||
UNKNOWN_PROVIDER: 10010;
|
||||
UNKNOWN_ROLE: 10011;
|
||||
UNKNOWN_TOKEN: 10012;
|
||||
UNKNOWN_USER: 10013;
|
||||
UNKNOWN_EMOJI: 10014;
|
||||
UNKNOWN_WEBHOOK: 10015;
|
||||
UNKNOWN_BAN: 10026;
|
||||
UNKNOWN_GUILD_TEMPLATE: 10057;
|
||||
BOT_PROHIBITED_ENDPOINT: 20001;
|
||||
BOT_ONLY_ENDPOINT: 20002;
|
||||
CHANNEL_HIT_WRITE_RATELIMIT: 20028;
|
||||
MAXIMUM_GUILDS: 30001;
|
||||
MAXIMUM_FRIENDS: 30002;
|
||||
MAXIMUM_PINS: 30003;
|
||||
MAXIMUM_ROLES: 30005;
|
||||
MAXIMUM_WEBHOOKS: 30007;
|
||||
MAXIMUM_REACTIONS: 30010;
|
||||
MAXIMUM_CHANNELS: 30013;
|
||||
MAXIMUM_ATTACHMENTS: 30015;
|
||||
MAXIMUM_INVITES: 30016;
|
||||
GUILD_ALREADY_HAS_TEMPLATE: 30031;
|
||||
UNAUTHORIZED: 40001;
|
||||
ACCOUNT_VERIFICATION_REQUIRED: 40002;
|
||||
REQUEST_ENTITY_TOO_LARGE: 40005;
|
||||
FEATURE_TEMPORARILY_DISABLED: 40006;
|
||||
USER_BANNED: 40007;
|
||||
ALREADY_CROSSPOSTED: 40033;
|
||||
MISSING_ACCESS: 50001;
|
||||
INVALID_ACCOUNT_TYPE: 50002;
|
||||
CANNOT_EXECUTE_ON_DM: 50003;
|
||||
EMBED_DISABLED: 50004;
|
||||
CANNOT_EDIT_MESSAGE_BY_OTHER: 50005;
|
||||
CANNOT_SEND_EMPTY_MESSAGE: 50006;
|
||||
CANNOT_MESSAGE_USER: 50007;
|
||||
CANNOT_SEND_MESSAGES_IN_VOICE_CHANNEL: 50008;
|
||||
CHANNEL_VERIFICATION_LEVEL_TOO_HIGH: 50009;
|
||||
OAUTH2_APPLICATION_BOT_ABSENT: 50010;
|
||||
MAXIMUM_OAUTH2_APPLICATIONS: 50011;
|
||||
INVALID_OAUTH_STATE: 50012;
|
||||
MISSING_PERMISSIONS: 50013;
|
||||
INVALID_AUTHENTICATION_TOKEN: 50014;
|
||||
NOTE_TOO_LONG: 50015;
|
||||
INVALID_BULK_DELETE_QUANTITY: 50016;
|
||||
CANNOT_PIN_MESSAGE_IN_OTHER_CHANNEL: 50019;
|
||||
INVALID_OR_TAKEN_INVITE_CODE: 50020;
|
||||
CANNOT_EXECUTE_ON_SYSTEM_MESSAGE: 50021;
|
||||
INVALID_OAUTH_TOKEN: 50025;
|
||||
BULK_DELETE_MESSAGE_TOO_OLD: 50034;
|
||||
INVALID_FORM_BODY: 50035;
|
||||
INVITE_ACCEPTED_TO_GUILD_NOT_CONTAINING_BOT: 50036;
|
||||
INVALID_API_VERSION: 50041;
|
||||
CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL: 50074;
|
||||
REACTION_BLOCKED: 90001;
|
||||
RESOURCE_OVERLOADED: 130000;
|
||||
}
|
||||
|
||||
type APIMessageContentResolvable = string | number | boolean | bigint | symbol | readonly StringResolvable[];
|
||||
|
|
@ -2671,6 +2679,7 @@ declare module 'discord.js' {
|
|||
host?: string;
|
||||
cdn?: string;
|
||||
invite?: string;
|
||||
template?: string;
|
||||
}
|
||||
|
||||
type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
||||
|
|
@ -2728,6 +2737,8 @@ declare module 'discord.js' {
|
|||
|
||||
type InviteResolvable = string;
|
||||
|
||||
type GuildTemplateResolvable = string;
|
||||
|
||||
type MembershipStates = 'INVITED' | 'ACCEPTED';
|
||||
|
||||
type MessageAdditions = MessageEmbed | MessageAttachment | (MessageEmbed | MessageAttachment)[];
|
||||
|
|
@ -2816,13 +2827,14 @@ declare module 'discord.js' {
|
|||
parse?: MessageMentionTypes[];
|
||||
roles?: Snowflake[];
|
||||
users?: Snowflake[];
|
||||
repliedUser?: boolean;
|
||||
}
|
||||
|
||||
type MessageMentionTypes = 'roles' | 'users' | 'everyone';
|
||||
|
||||
interface MessageOptions {
|
||||
tts?: boolean;
|
||||
nonce?: string;
|
||||
nonce?: string | number;
|
||||
content?: StringResolvable;
|
||||
embed?: MessageEmbed | MessageEmbedOptions;
|
||||
disableMentions?: 'none' | 'all' | 'everyone';
|
||||
|
|
@ -2830,7 +2842,7 @@ declare module 'discord.js' {
|
|||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||
code?: string | boolean;
|
||||
split?: boolean | SplitOptions;
|
||||
reply?: UserResolvable;
|
||||
replyTo?: MessageResolvable;
|
||||
}
|
||||
|
||||
type MessageReactionResolvable = MessageReaction | Snowflake;
|
||||
|
|
@ -2860,7 +2872,8 @@ declare module 'discord.js' {
|
|||
| 'USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3'
|
||||
| 'CHANNEL_FOLLOW_ADD'
|
||||
| 'GUILD_DISCOVERY_DISQUALIFIED'
|
||||
| 'GUILD_DISCOVERY_REQUALIFIED';
|
||||
| 'GUILD_DISCOVERY_REQUALIFIED'
|
||||
| 'REPLY';
|
||||
|
||||
interface OverwriteData {
|
||||
allow?: PermissionResolvable;
|
||||
|
|
@ -3018,6 +3031,7 @@ declare module 'discord.js' {
|
|||
| 'attachments'
|
||||
| 'channel'
|
||||
| 'deletable'
|
||||
| 'crosspostable'
|
||||
| 'editable'
|
||||
| 'mentions'
|
||||
| 'pinnable'
|
||||
|
|
@ -3029,6 +3043,7 @@ declare module 'discord.js' {
|
|||
attachments: Message['attachments'];
|
||||
channel: Message['channel'];
|
||||
readonly deletable: boolean;
|
||||
readonly crosspostable: boolean;
|
||||
readonly editable: boolean;
|
||||
readonly edits: Message['edits'];
|
||||
embeds: Message['embeds'];
|
||||
|
|
@ -3045,11 +3060,9 @@ declare module 'discord.js' {
|
|||
|
||||
type PartialTypes = 'USER' | 'CHANNEL' | 'GUILD_MEMBER' | 'MESSAGE' | 'REACTION';
|
||||
|
||||
interface PartialUser
|
||||
extends Omit<Partialize<User, 'bot' | 'flags' | 'locale' | 'system' | 'tag' | 'username'>, 'deleted'> {
|
||||
interface PartialUser extends Omit<Partialize<User, 'bot' | 'flags' | 'system' | 'tag' | 'username'>, 'deleted'> {
|
||||
bot: User['bot'];
|
||||
flags: User['flags'];
|
||||
locale: User['locale'];
|
||||
system: User['system'];
|
||||
readonly tag: null;
|
||||
username: null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue