【发布时间】:2021-08-17 07:53:57
【问题描述】:
我今天遇到了这个错误,试图从一个 youtube 视频中更改我的命令处理程序的一点点。视频来自 4 月,它似乎对这个人有用,但对我来说却没有。我尝试了很多东西,但我没有得到任何线索。我对此不太好,但我想像许多其他人一样开始,这个社区非常好,对我帮助很大,非常感谢你对我的支持!!我希望我能过去这个问题。
const Timeout = new Discord.Collection();
const bot = new Discord.Client();
const prefix = '$';
bot.commands = new Discord.Collection();
const commandFolders = readdirSync('./commands');
const ms = require('ms');
const {readdirSync , read} = require('fs');
for(const folder of commandsFolders){
const commandFiles = readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${folder}/${files}`);
bot.commands.set(command.name, command);
}
}
bot.on("error" , console.error);
bot.once('ready' , () => {
console.log('M-am trezit din morti!');
});
bot.on("message" , async (message) =>{
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
if(message.content.startsWith(prefix)){
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = bot.command.get(commandName) || bot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if(!command) return;
if (command) {
if(command.cooldown){
if(Timeout.has(`${command.name}${message.author.id}`)) return message.channel.send(`Te rog asteapta! \`${ms(Timeout.get (`${command.name}${message.author.id}`) - Date.now(), {long: true})}\`Pana folosesti comanda din nou!`);
command.run(bot, message, args)
Timeout.set(`${command.name}${message.author.id}` , Date.now() + command.cooldown)
setTimeout(() =>{
Timeout.delete(`${coomand.name}${message.author.id}`)
}, command.cooldown)
} else command.run(bot, message, args);
}
}
})
【问题讨论】:
标签: javascript npm discord bots