mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
refactor: rename events to be consistent with WS names (#6010)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -49,7 +49,7 @@ client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
client.on('messageCreate', message => {
|
||||
if (message.content === 'ping') {
|
||||
message.channel.send('pong');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ const Action = require('./Action');
|
||||
const { Events, InteractionTypes, MessageComponentTypes } = require('../../util/Constants');
|
||||
const Structures = require('../../util/Structures');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class InteractionCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
@@ -37,12 +39,25 @@ class InteractionCreateAction extends Action {
|
||||
return;
|
||||
}
|
||||
|
||||
const interaction = new InteractionType(client, data);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interactionCreate
|
||||
* @param {Interaction} interaction The interaction which was created
|
||||
*/
|
||||
client.emit(Events.INTERACTION_CREATE, interaction);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interaction
|
||||
* @param {Interaction} interaction The interaction which was created
|
||||
* @deprecated Use {@link Client#interactionCreate} instead
|
||||
*/
|
||||
client.emit(Events.INTERACTION_CREATE, new InteractionType(client, data));
|
||||
if (client.emit('interaction', interaction) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The interaction event is deprecated. Use interactionCreate instead', 'DeprecationWarning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class MessageCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
@@ -25,10 +27,22 @@ class MessageCreateAction extends Action {
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#message
|
||||
* @event Client#messageCreate
|
||||
* @param {Message} message The created message
|
||||
*/
|
||||
client.emit(Events.MESSAGE_CREATE, message);
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#message
|
||||
* @param {Message} message The created message
|
||||
* @deprecated Use {@link Client#messageCreate} instead
|
||||
*/
|
||||
if (client.emit('message', message) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The message event is deprecated. Use messageCreate instead', 'DeprecationWarning');
|
||||
}
|
||||
|
||||
return { message };
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ exports.Events = {
|
||||
CHANNEL_DELETE: 'channelDelete',
|
||||
CHANNEL_UPDATE: 'channelUpdate',
|
||||
CHANNEL_PINS_UPDATE: 'channelPinsUpdate',
|
||||
MESSAGE_CREATE: 'message',
|
||||
MESSAGE_CREATE: 'messageCreate',
|
||||
MESSAGE_DELETE: 'messageDelete',
|
||||
MESSAGE_UPDATE: 'messageUpdate',
|
||||
MESSAGE_BULK_DELETE: 'messageDeleteBulk',
|
||||
@@ -275,7 +275,7 @@ exports.Events = {
|
||||
VOICE_STATE_UPDATE: 'voiceStateUpdate',
|
||||
TYPING_START: 'typingStart',
|
||||
WEBHOOKS_UPDATE: 'webhookUpdate',
|
||||
INTERACTION_CREATE: 'interaction',
|
||||
INTERACTION_CREATE: 'interactionCreate',
|
||||
ERROR: 'error',
|
||||
WARN: 'warn',
|
||||
DEBUG: 'debug',
|
||||
|
||||
@@ -42,7 +42,7 @@ client.on('debug', console.log);
|
||||
client.on('error', m => console.log('debug', new Error(m).stack));
|
||||
client.on('reconnecting', m => console.log('reconnecting', m));
|
||||
|
||||
client.on('message', message => {
|
||||
client.on('messageCreate', message => {
|
||||
if (true) {
|
||||
if (message.content === 'makechann') {
|
||||
if (message.channel.guild) {
|
||||
@@ -178,7 +178,7 @@ function chanLoop(channel) {
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
client.on('message', msg => {
|
||||
client.on('messageCreate', msg => {
|
||||
if (msg.content.startsWith('?raw')) {
|
||||
msg.channel.send(`\`\`\`${msg.content}\`\`\``);
|
||||
}
|
||||
@@ -200,7 +200,7 @@ client.on('message', msg => {
|
||||
|
||||
let disp, con;
|
||||
|
||||
client.on('message', msg => {
|
||||
client.on('messageCreate', msg => {
|
||||
if (msg.content.startsWith('/play')) {
|
||||
console.log('I am now going to play', msg.content);
|
||||
const chan = msg.content
|
||||
@@ -243,7 +243,7 @@ client.on('messageReactionRemove', (reaction, user) => {
|
||||
reaction.message.channel.send(`${user.username} removed reaction ${reaction.emoji}, count is now ${reaction.count}`);
|
||||
});
|
||||
|
||||
client.on('message', m => {
|
||||
client.on('messageCreate', m => {
|
||||
if (m.content.startsWith('#reactions')) {
|
||||
const mID = m.content.split(' ')[1];
|
||||
m.channel.messages.fetch(mID).then(rM => {
|
||||
|
||||
@@ -89,7 +89,7 @@ const tests = [
|
||||
m => m.channel.send('Done!'),
|
||||
];
|
||||
|
||||
client.on('message', async message => {
|
||||
client.on('messageCreate', async message => {
|
||||
if (message.author.id !== owner) return;
|
||||
const match = message.content.match(/^do (.+)$/);
|
||||
if (match && match[1] === 'it') {
|
||||
|
||||
@@ -7,10 +7,9 @@ const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
|
||||
shards: process.argv[2],
|
||||
shardCount: process.argv[3],
|
||||
intents: Discord.Intents.NON_PRIVILEGED,
|
||||
});
|
||||
|
||||
client.on('message', msg => {
|
||||
client.on('messageCreate', msg => {
|
||||
if (msg.content.startsWith('?eval') && msg.author.id === '66564597481480192') {
|
||||
try {
|
||||
const com = eval(msg.content.split(' ').slice(1).join(' '));
|
||||
|
||||
@@ -6,7 +6,7 @@ const { Client } = require('../src');
|
||||
const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });
|
||||
client
|
||||
.on('ready', () => console.log('ready'))
|
||||
.on('message', async message => {
|
||||
.on('messageCreate', async message => {
|
||||
try {
|
||||
const templates = await message.guild.fetchTemplates();
|
||||
if (!templates.size) {
|
||||
|
||||
@@ -9,7 +9,6 @@ const log = (...args) => console.log(process.uptime().toFixed(3), ...args);
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
|
||||
shardCount: 2,
|
||||
intents: Discord.Intents.NON_PRIVILEGED,
|
||||
});
|
||||
|
||||
client.on('debug', log);
|
||||
@@ -36,7 +35,7 @@ const commands = {
|
||||
ping: message => message.channel.send('pong'),
|
||||
};
|
||||
|
||||
client.on('message', message => {
|
||||
client.on('messageCreate', message => {
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
|
||||
message.content = message.content.replace(prefix, '').trim().split(' ');
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/* eslint no-console: 0 */
|
||||
'use strict';
|
||||
|
||||
const ytdl = require('ytdl-core');
|
||||
const auth = require('./auth.js');
|
||||
const { Client, Intents } = require('../src');
|
||||
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_PRESENCES],
|
||||
partials: [],
|
||||
});
|
||||
|
||||
client
|
||||
.login(auth.token)
|
||||
.then(() => console.log('logged'))
|
||||
.catch(console.error);
|
||||
|
||||
const connections = new Map();
|
||||
|
||||
client.on('debug', console.log);
|
||||
client.on('error', console.log);
|
||||
|
||||
process.on('unhandledRejection', console.log);
|
||||
|
||||
client.on('presenceUpdate', (a, b) => {
|
||||
if (b.userID !== '66564597481480192') return;
|
||||
console.log(a ? a.status : null, b.status, b.user.username);
|
||||
});
|
||||
|
||||
client.on('messageDelete', async m => {
|
||||
if (m.channel.id !== '80426989059575808') return;
|
||||
console.log(m.channel.recipient);
|
||||
console.log(m.channel.partial);
|
||||
await m.channel.fetch();
|
||||
console.log('\n\n\n\n');
|
||||
console.log(m.channel);
|
||||
});
|
||||
|
||||
client.on('message', m => {
|
||||
if (!m.guild) return;
|
||||
if (m.author.id !== '66564597481480192') return;
|
||||
if (m.content.startsWith('/join')) {
|
||||
const channel = m.guild.channels.cache.get(m.content.split(' ')[1]) ?? m.member.voice.channel;
|
||||
if (channel && channel.type === 'voice') {
|
||||
channel.join().then(conn => {
|
||||
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.channel.send('ok!');
|
||||
conn.play(ytdl('https://www.youtube.com/watch?v=_XXOSf0s2nk', { filter: 'audioonly' }, { passes: 3 }));
|
||||
});
|
||||
} else {
|
||||
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(' '));
|
||||
m.channel.send(com, { code: true });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
m.channel.send(String(e), { code: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -93,7 +93,7 @@ const tests = [
|
||||
(m, hook) => hook.send('Done!'),
|
||||
];
|
||||
|
||||
client.on('message', async message => {
|
||||
client.on('messageCreate', async message => {
|
||||
if (message.author.id !== owner) return;
|
||||
const match = message.content.match(/^do (.+)$/);
|
||||
const hooks = [
|
||||
|
||||
8
typings/index.d.ts
vendored
8
typings/index.d.ts
vendored
@@ -680,7 +680,7 @@ declare module 'discord.js' {
|
||||
CHANNEL_DELETE: 'channelDelete';
|
||||
CHANNEL_UPDATE: 'channelUpdate';
|
||||
CHANNEL_PINS_UPDATE: 'channelPinsUpdate';
|
||||
MESSAGE_CREATE: 'message';
|
||||
MESSAGE_CREATE: 'messageCreate';
|
||||
MESSAGE_DELETE: 'messageDelete';
|
||||
MESSAGE_UPDATE: 'messageUpdate';
|
||||
MESSAGE_BULK_DELETE: 'messageDeleteBulk';
|
||||
@@ -700,7 +700,7 @@ declare module 'discord.js' {
|
||||
VOICE_STATE_UPDATE: 'voiceStateUpdate';
|
||||
TYPING_START: 'typingStart';
|
||||
WEBHOOKS_UPDATE: 'webhookUpdate';
|
||||
INTERACTION_CREATE: 'interaction';
|
||||
INTERACTION_CREATE: 'interactionCreate';
|
||||
ERROR: 'error';
|
||||
WARN: 'warn';
|
||||
DEBUG: 'debug';
|
||||
@@ -3086,7 +3086,9 @@ declare module 'discord.js' {
|
||||
guildUpdate: [oldGuild: Guild, newGuild: Guild];
|
||||
inviteCreate: [invite: Invite];
|
||||
inviteDelete: [invite: Invite];
|
||||
/** @deprecated Use messageCreate instead */
|
||||
message: [message: Message];
|
||||
messageCreate: [message: Message];
|
||||
messageDelete: [message: Message | PartialMessage];
|
||||
messageReactionRemoveAll: [message: Message | PartialMessage];
|
||||
messageReactionRemoveEmoji: [reaction: MessageReaction];
|
||||
@@ -3115,7 +3117,9 @@ declare module 'discord.js' {
|
||||
userUpdate: [oldUser: User | PartialUser, newUser: User];
|
||||
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
|
||||
webhookUpdate: [channel: TextChannel];
|
||||
/** @deprecated Use interactionCreate instead */
|
||||
interaction: [interaction: Interaction];
|
||||
interactionCreate: [interaction: Interaction];
|
||||
shardDisconnect: [closeEvent: CloseEvent, shardID: number];
|
||||
shardError: [error: Error, shardID: number];
|
||||
shardReady: [shardID: number, unavailableGuilds: Set<Snowflake> | undefined];
|
||||
|
||||
@@ -365,7 +365,7 @@ client.on('messageReactionRemoveAll', async message => {
|
||||
// This is to check that stuff is the right type
|
||||
declare const assertIsMessage: (m: Promise<Message>) => void;
|
||||
|
||||
client.on('message', ({ channel }) => {
|
||||
client.on('messageCreate', ({ channel }) => {
|
||||
assertIsMessage(channel.send('string'));
|
||||
assertIsMessage(channel.send({}));
|
||||
assertIsMessage(channel.send({ embeds: [] }));
|
||||
|
||||
Reference in New Issue
Block a user