As you can see from the docs, the event message
is deprecated. You can use instead a listener for the event messageCreated
if you want to listen for any new message.
So you can try something like
client.on('messageCreate', async msg => {
if (msg.content === "ping") {
console.log("ping");
msg.reply("pong");
}
});
EDIT:
As @chickensalt pointed out, you have to declare in your Intents
the appropriate one for handling messages, that is Intents.FLAGS.GUILD_MESSAGES
. So, when creating your Client
:
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intent.FLAGS.GUILD_MESSAGES] });
But remember to use the correct Intent for your needs, because you could have some trouble in handling memory correctly. As the docs suggests:
For larger bots, client state can grow to be quite large. We recommend only storing objects in memory that are needed for a bot's operation. Many bots, for example, just respond to user input through chat commands. These bots may only need to keep guild information (like guild/channel roles and permissions) in memory, since MESSAGE_CREATE
and MESSAGE_UPDATE
events have the full member object available.