DeprecationWarning:消息事件已被弃用.改用 messageCreate

2022-01-10 00:00:00 bots javascript discord.js

我对不和谐机器人相对较新,但我一生都无法弄清楚为什么我不断收到此错误 - 我试图用 message creat 替换 message,但它似乎根本不起作用.这是我的代码:

I am relatively new to discord bots but I cant for the life of me figure out why I keep getting this error - I have tried to replace message with message creat but it doesn't seem to work at all. Here is my code:

client.on('message', (message) => {
    if(message.author.client) return; 
    if(message.channel.type !== 'text') return;
    let prefix = '!'; 
    let MessageArray = message.content.split(' ');
    let cmd = MessageArray(0).slice(prefix.length)
    let args = MessageArray.slice(1)

    if(!message.content.startsWith(prefix)) return; 

    if(cmd == 'hello') {
        message.channel.send({ messages: ['hello'] });
    })

推荐答案

message 事件已重命名为 messageCreate.使用 message 仍然有效,但在您切换之前,您会收到弃用警告.

The message event has been renamed to messageCreate. Using message will still work, but you'll receive a deprecation warning until you switch over.

client.on("messageCreate", (message) => {
    if (message.author.client) return;
    if (message.channel.type !== "text") return;
    let prefix = "!";
    let MessageArray = message.content.split(" ");
    let cmd = MessageArray(0).slice(prefix.length);
    let args = MessageArray.slice(1);

    if (!message.content.startsWith(prefix)) return;

    if (cmd == "hello") {
        message.channel.send({ messages: ["hello"] });
    }
});

相关文章