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

时间:2023-02-11
本文介绍了DeprecationWarning:消息事件已被弃用.改用 messageCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对不和谐机器人相对较新,但我一生都无法弄清楚为什么我不断收到此错误 - 我试图用 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"] });
    }
});

这篇关于DeprecationWarning:消息事件已被弃用.改用 messageCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:Discord.js 带空格的参数 下一篇:我正在尝试编写一个显示我的我的世界服务器状

相关文章

最新文章