首页 > 解决方案 > 有没有办法否定 message.content?

问题描述

如果它不以“播放!”开头,我正在尝试让我的机器人从一个特定频道中删除所有消息。

我试过了(message.channel === (channel number) && !message.content.('play!'))。这似乎不起作用。

bot.on('message', message=>{

    //delete all in channel if not beginning with play! starts here
    if (message.channel === (the channel) && !message.content.('play!')) {
        message.delete(50);
    }
    // and ends here
})

我希望它能删除所有不以 play 开头的消息!并且在频道中。

标签: javascriptdiscorddiscord.js

解决方案


你应该使用

if (message.channel === (the channel) && !message.content.startsWith('play!')) {
    return message.delete(50);
}

因此!message.content.startsWith('play!')return message.delete(50);删除该消息并停止对该消息执行任何其他操作。


推荐阅读