mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
fix: update clientReady event name references (#10632)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"root": true,
|
"root": true,
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": ["src/**/*.js"],
|
"files": ["src/**/*.js", "test/**/*.js"],
|
||||||
"extends": ["eslint:recommended"],
|
"extends": ["eslint:recommended"],
|
||||||
"plugins": ["import"],
|
"plugins": ["import"],
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
|
|||||||
@@ -83,14 +83,15 @@ try {
|
|||||||
Afterwards we can create a quite simple example bot:
|
Afterwards we can create a quite simple example bot:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { Client, GatewayIntentBits } from 'discord.js';
|
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on(Events.ClientReady, readyClient => {
|
||||||
console.log(`Logged in as ${client.user.tag}!`);
|
console.log(`Logged in as ${readyClient.user.tag}!`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('interactionCreate', async interaction => {
|
client.on(Events.InteractionCreate, async interaction => {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
if (interaction.commandName === 'ping') {
|
if (interaction.commandName === 'ping') {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* @property {string} ChannelDelete channelDelete
|
* @property {string} ChannelDelete channelDelete
|
||||||
* @property {string} ChannelPinsUpdate channelPinsUpdate
|
* @property {string} ChannelPinsUpdate channelPinsUpdate
|
||||||
* @property {string} ChannelUpdate channelUpdate
|
* @property {string} ChannelUpdate channelUpdate
|
||||||
* @property {string} ClientReady ready
|
* @property {string} ClientReady clientReady
|
||||||
* @property {string} Debug debug
|
* @property {string} Debug debug
|
||||||
* @property {string} EntitlementCreate entitlementCreate
|
* @property {string} EntitlementCreate entitlementCreate
|
||||||
* @property {string} EntitlementUpdate entitlementUpdate
|
* @property {string} EntitlementUpdate entitlementUpdate
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
const assert = require('node:assert');
|
const assert = require('node:assert');
|
||||||
const { ChannelType, GatewayIntentBits } = require('discord-api-types/v10');
|
const { ChannelType, GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { token } = require('./auth');
|
const { token } = require('./auth');
|
||||||
const { Client } = require('../src');
|
const { Client, Events } = require('../src');
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
||||||
|
|
||||||
client.on('ready', async () => {
|
client.on(Events.ClientReady, async readyClient => {
|
||||||
try {
|
try {
|
||||||
const guild = await client.guilds.create('testing', {
|
const guild = await readyClient.guilds.create('testing', {
|
||||||
channels: [
|
channels: [
|
||||||
{ name: 'afk channel', type: ChannelType.GuildVoice, id: 0 },
|
{ name: 'afk channel', type: ChannelType.GuildVoice, id: 0 },
|
||||||
{ name: 'system-channel', id: 1 },
|
{ name: 'system-channel', id: 1 },
|
||||||
@@ -26,7 +26,7 @@ client.on('ready', async () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
await client.destroy();
|
await readyClient.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { token, owner } = require('./auth.js');
|
const { token, owner } = require('./auth.js');
|
||||||
const { Client } = require('../src');
|
const { Client, Events } = require('../src');
|
||||||
const { ChannelType, GatewayIntentBits } = require('discord-api-types/v10');
|
const { ChannelType, GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
|
|
||||||
console.time('magic');
|
console.time('magic');
|
||||||
@@ -24,18 +24,18 @@ client
|
|||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
|
||||||
// Fetch all members in a new guild
|
// Fetch all members in a new guild
|
||||||
client.on('guildCreate', guild =>
|
client.on(Events.GuildCreate, guild =>
|
||||||
guild.members.fetch().catch(err => console.log(`Failed to fetch all members: ${err}\n${err.stack}`)),
|
guild.members.fetch().catch(err => console.log(`Failed to fetch all members: ${err}\n${err.stack}`)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetch all members in a newly available guild
|
// Fetch all members in a newly available guild
|
||||||
client.on('guildUpdate', (oldGuild, newGuild) =>
|
client.on(Events.GuildUpdate, (oldGuild, newGuild) =>
|
||||||
!oldGuild.available && newGuild.available
|
!oldGuild.available && newGuild.available
|
||||||
? newGuild.members.fetch().catch(err => console.log(`Failed to fetch all members: ${err}\n${err.stack}`))
|
? newGuild.members.fetch().catch(err => console.log(`Failed to fetch all members: ${err}\n${err.stack}`))
|
||||||
: Promise.resolve(),
|
: Promise.resolve(),
|
||||||
);
|
);
|
||||||
|
|
||||||
client.on('ready', async () => {
|
client.on(Events.ClientReady, async () => {
|
||||||
// Fetch all members for initially available guilds
|
// Fetch all members for initially available guilds
|
||||||
try {
|
try {
|
||||||
const promises = client.guilds.cache.map(guild => (guild.available ? guild.members.fetch() : Promise.resolve()));
|
const promises = client.guilds.cache.map(guild => (guild.available ? guild.members.fetch() : Promise.resolve()));
|
||||||
@@ -48,12 +48,11 @@ client.on('ready', async () => {
|
|||||||
console.timeEnd('magic');
|
console.timeEnd('magic');
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('debug', console.log);
|
client.on(Events.Debug, console.log);
|
||||||
|
|
||||||
client.on('error', m => console.log('debug', new Error(m).stack));
|
client.on(Events.Error, m => console.log('debug', new Error(m).stack));
|
||||||
client.on('reconnecting', m => console.log('reconnecting', m));
|
|
||||||
|
|
||||||
client.on('messageCreate', message => {
|
client.on(Events.MessageCreate, message => {
|
||||||
if (true) {
|
if (true) {
|
||||||
if (message.content === 'makechann') {
|
if (message.content === 'makechann') {
|
||||||
if (message.channel.guild) {
|
if (message.channel.guild) {
|
||||||
@@ -182,7 +181,7 @@ function chanLoop(channel) {
|
|||||||
channel.setName(`${channel.name}a`).then(chanLoop).catch(console.error);
|
channel.setName(`${channel.name}a`).then(chanLoop).catch(console.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on('messageCreate', msg => {
|
client.on(Events.MessageCreate, msg => {
|
||||||
if (msg.content.startsWith('?raw')) {
|
if (msg.content.startsWith('?raw')) {
|
||||||
msg.channel.send(`\`\`\`${msg.content}\`\`\``);
|
msg.channel.send(`\`\`\`${msg.content}\`\`\``);
|
||||||
}
|
}
|
||||||
@@ -197,17 +196,17 @@ client.on('messageCreate', msg => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageReactionAdd', (reaction, user) => {
|
client.on(Events.MessageReactionAdd, (reaction, user) => {
|
||||||
if (reaction.message.channelId !== '222086648706498562') return;
|
if (reaction.message.channelId !== '222086648706498562') return;
|
||||||
reaction.message.channel.send(`${user.username} added reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
reaction.message.channel.send(`${user.username} added reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageReactionRemove', (reaction, user) => {
|
client.on(Events.MessageReactionRemove, (reaction, user) => {
|
||||||
if (reaction.message.channelId !== '222086648706498562') return;
|
if (reaction.message.channelId !== '222086648706498562') return;
|
||||||
reaction.message.channel.send(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
reaction.message.channel.send(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageCreate', m => {
|
client.on(Events.MessageCreate, m => {
|
||||||
if (m.content.startsWith('#reactions')) {
|
if (m.content.startsWith('#reactions')) {
|
||||||
const mId = m.content.split(' ')[1];
|
const mId = m.content.split(' ')[1];
|
||||||
m.channel.messages.fetch(mId).then(rM => {
|
m.channel.messages.fetch(mId).then(rM => {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { token, guildId, channelId, messageId } = require('./auth.js');
|
const { token, guildId, channelId, messageId } = require('./auth.js');
|
||||||
const { Client, ReactionCollector } = require('../src');
|
const { Client, Events, ReactionCollector } = require('../src');
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions],
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('ready', async () => {
|
client.on(Events.ClientReady, async readyClient => {
|
||||||
const guild = client.guilds.cache.get(guildId);
|
const guild = readyClient.guilds.cache.get(guildId);
|
||||||
|
|
||||||
const channel = guild.channels.cache.get(channelId);
|
const channel = guild.channels.cache.get(channelId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Buffer } = require('node:buffer');
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
@@ -8,7 +9,7 @@ const util = require('node:util');
|
|||||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { fetch } = require('undici');
|
const { fetch } = require('undici');
|
||||||
const { owner, token } = require('./auth.js');
|
const { owner, token } = require('./auth.js');
|
||||||
const { Client, MessageAttachment, Embed } = require('../src');
|
const { Client, MessageAttachment, Embed, Events } = require('../src');
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ const tests = [
|
|||||||
m => m.channel.send('Done!'),
|
m => m.channel.send('Done!'),
|
||||||
];
|
];
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on(Events.MessageCreate, async message => {
|
||||||
if (message.author.id !== owner) return;
|
if (message.author.id !== owner) return;
|
||||||
const match = message.content.match(/^do (.+)$/);
|
const match = message.content.match(/^do (.+)$/);
|
||||||
if (match?.[1] === 'it') {
|
if (match?.[1] === 'it') {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const process = require('node:process');
|
|||||||
const { setTimeout } = require('node:timers');
|
const { setTimeout } = require('node:timers');
|
||||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { token } = require('./auth.json');
|
const { token } = require('./auth.json');
|
||||||
const { Client } = require('../src');
|
const { Client, Events } = require('../src');
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
|
||||||
@@ -12,7 +12,7 @@ const client = new Client({
|
|||||||
shardCount: process.argv[3],
|
shardCount: process.argv[3],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageCreate', msg => {
|
client.on(Events.ClientReady, msg => {
|
||||||
if (msg.content.startsWith('?eval') && msg.author.id === '66564597481480192') {
|
if (msg.content.startsWith('?eval') && msg.author.id === '66564597481480192') {
|
||||||
try {
|
try {
|
||||||
const com = eval(msg.content.split(' ').slice(1).join(' '));
|
const com = eval(msg.content.split(' ').slice(1).join(' '));
|
||||||
@@ -25,9 +25,9 @@ client.on('messageCreate', msg => {
|
|||||||
|
|
||||||
process.send(123);
|
process.send(123);
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on(Events.ClientReady, readyClient => {
|
||||||
console.log('Ready', client.options.shards);
|
console.log('Ready', readyClient.options.shards);
|
||||||
if (client.options.shards === 0) {
|
if (readyClient.options.shards === 0) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
console.log('kek dying');
|
console.log('kek dying');
|
||||||
await client.destroy();
|
await client.destroy();
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { token } = require('./auth');
|
const { token } = require('./auth');
|
||||||
const { Client, GatewayIntentBits } = require('../src');
|
const { Client, Events, GatewayIntentBits } = require('../src');
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
||||||
|
|
||||||
client
|
client
|
||||||
.on('ready', () => console.log('ready'))
|
.on(Events.ClientReady, () => console.log('ready'))
|
||||||
.on('messageCreate', async message => {
|
.on(Events.MessageCreate, async message => {
|
||||||
try {
|
try {
|
||||||
const templates = await message.guild.fetchTemplates();
|
const templates = await message.guild.fetchTemplates();
|
||||||
if (!templates.size) {
|
if (!templates.size) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { token, prefix, owner } = require('./auth.js');
|
const { token, prefix, owner } = require('./auth.js');
|
||||||
const { Client } = require('../src');
|
const { Client, Events, RESTEvents } = require('../src');
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
||||||
@@ -13,12 +13,12 @@ const client = new Client({
|
|||||||
shardCount: 2,
|
shardCount: 2,
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('debug', log);
|
client.on(Events.Debug, log);
|
||||||
client.on('ready', () => {
|
client.on(Events.ClientReady, () => {
|
||||||
log('READY', client.user.tag, client.user.id);
|
log('READY', client.user.tag, client.user.id);
|
||||||
});
|
});
|
||||||
client.on('rateLimit', log);
|
client.rest.on(RESTEvents.RateLimited, log);
|
||||||
client.on('error', console.error);
|
client.on(Events.Error, console.error);
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
eval: message => {
|
eval: message => {
|
||||||
@@ -37,7 +37,7 @@ const commands = {
|
|||||||
ping: message => message.channel.send('pong'),
|
ping: message => message.channel.send('pong'),
|
||||||
};
|
};
|
||||||
|
|
||||||
client.on('messageCreate', message => {
|
client.on(Events.MessageCreate, message => {
|
||||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
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(' ');
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
const { GatewayIntentBits } = require('discord-api-types/v10');
|
const { GatewayIntentBits } = require('discord-api-types/v10');
|
||||||
const { token, prefix, owner } = require('./auth.js');
|
const { token, prefix, owner } = require('./auth.js');
|
||||||
const { Client, Options, codeBlock } = require('../src');
|
const { Client, Events, Options, RESTEvents, codeBlock } = require('../src');
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
||||||
@@ -25,12 +25,12 @@ const client = new Client({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('debug', log);
|
client.on(Events.Debug, log);
|
||||||
client.on('ready', () => {
|
client.on(Events.ClientReady, () => {
|
||||||
log('READY', client.user.tag, client.user.id);
|
log('READY', client.user.tag, client.user.id);
|
||||||
});
|
});
|
||||||
client.on('rateLimit', log);
|
client.rest.on(RESTEvents.RateLimited, log);
|
||||||
client.on('error', console.error);
|
client.on(Events.Error, console.error);
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
eval: message => {
|
eval: message => {
|
||||||
@@ -49,7 +49,7 @@ const commands = {
|
|||||||
ping: message => message.channel.send('pong'),
|
ping: message => message.channel.send('pong'),
|
||||||
};
|
};
|
||||||
|
|
||||||
client.on('messageCreate', message => {
|
client.on(Events.MessageCreate, message => {
|
||||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
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(' ');
|
||||||
|
|||||||
Reference in New Issue
Block a user