diff --git a/README.md b/README.md index 80bb8573e9bc..cda8987cf84d 100644 --- a/README.md +++ b/README.md @@ -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'); } diff --git a/src/client/actions/InteractionCreate.js b/src/client/actions/InteractionCreate.js index e30c3312e1f1..3938af811692 100644 --- a/src/client/actions/InteractionCreate.js +++ b/src/client/actions/InteractionCreate.js @@ -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'); + } } } diff --git a/src/client/actions/MessageCreate.js b/src/client/actions/MessageCreate.js index 17a7189dea1d..ccb5906c3b16 100644 --- a/src/client/actions/MessageCreate.js +++ b/src/client/actions/MessageCreate.js @@ -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 }; } diff --git a/src/util/Constants.js b/src/util/Constants.js index 713a7f94f1f7..3c4325879ad9 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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', diff --git a/test/random.js b/test/random.js index e09e23bb217d..78395db49ab7 100644 --- a/test/random.js +++ b/test/random.js @@ -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 => { diff --git a/test/sendtest.js b/test/sendtest.js index 205ee80da6c3..3d571fc45a1a 100644 --- a/test/sendtest.js +++ b/test/sendtest.js @@ -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') { diff --git a/test/shard.js b/test/shard.js index fd113d664281..4ea5f5428736 100644 --- a/test/shard.js +++ b/test/shard.js @@ -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(' ')); diff --git a/test/templateCreateGuild.js b/test/templateCreateGuild.js index 8e2576a8ef70..78c1a3b4ab63 100644 --- a/test/templateCreateGuild.js +++ b/test/templateCreateGuild.js @@ -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) { diff --git a/test/tester1000.js b/test/tester1000.js index 45deed3d255f..d104305819b1 100644 --- a/test/tester1000.js +++ b/test/tester1000.js @@ -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(' '); diff --git a/test/voice.js b/test/voice.js deleted file mode 100644 index 565456cc5c03..000000000000 --- a/test/voice.js +++ /dev/null @@ -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 }); - } - } -}); diff --git a/test/webhooktest.js b/test/webhooktest.js index 094a1ef72f75..74950ba5f19b 100644 --- a/test/webhooktest.js +++ b/test/webhooktest.js @@ -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 = [ diff --git a/typings/index.d.ts b/typings/index.d.ts index 70e10be03dc8..d60c363c4dce 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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 | undefined]; diff --git a/typings/index.ts b/typings/index.ts index cd5df0a07858..a11c13659974 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -365,7 +365,7 @@ client.on('messageReactionRemoveAll', async message => { // This is to check that stuff is the right type declare const assertIsMessage: (m: Promise) => void; -client.on('message', ({ channel }) => { +client.on('messageCreate', ({ channel }) => { assertIsMessage(channel.send('string')); assertIsMessage(channel.send({})); assertIsMessage(channel.send({ embeds: [] }));