Discord.js通过现有功能删除消息

问题描述 投票:0回答:1

问题在执行我的代码时,我现在确实没有任何错误,但是想添加到函数中,但是尝试了几乎所有处理它的方法。此时,由于混乱和沮丧,该变量已被删除。

需要发生的是,启动命令的用户,他们的消息在短暂的延迟后被删除。我已经尝试了message.delete(1000)和v12的其他变体,但没有运气。无法通过我的活动函数传递“消息”变量?

也许我已经完全离开了,只是让自己难受,我不知道。老实说我无法弄清楚message.delete感到尴尬。请帮忙。为无知而道歉。

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = "";
const PREFIX = "!";

const fs = require('fs');
bot.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    bot.commands.set(command.name, command);
}


bot.on('ready', () => {
    console.log("The bot is active and ready to go!");
});

      bot.on('message', function(message) {
        if(message.content[0] === PREFIX) {
            let command = message.content.substring(message.content.indexOf(" ") + 1, message.content.length);

        }
    });

bot.on('message', message => {
    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {

        case "crash":
            bot.commands.get('crash').execute(message, args);
        break;

        case "hello":
            bot.commands.get('hello').execute(message, args);
        break;

        case "purge":
            bot.commands.get('purge').execute(message, args);
        break;
    }

});

bot.login(token);

这里是“ crash.js”的示例供参考。不知道我是否需要从那里执行删除吗?

module.exports = {
    name: 'crash',
    description: "Crash",
    execute(message, args){
        message.author.send("Here is the link you requested");
    }
}
javascript discord discord.js message
1个回答
0
投票

您可以在模块内执行删除。该消息作为完整对象传递,因此您只需对其调用delete方法。但是,Options是一个对象,表示需要这样定义。为了清楚起见,我将使用另一个变量,但是可以内联完成。

let options = {
    timeout: 1000
    reason: 'Because I said so.'
}

message.delete(options);

或内联...

message.delete({timeout: 1000});
© www.soinside.com 2019 - 2024. All rights reserved.