我正在尝试执行静音命令,但是当尝试为我的数据库设置ROLE ID时,它不会设置它,有人知道如何解决此问题吗?
我正在使用的是:discord.js,quick.db
我已经对这个问题进行了一些研究,我可以找到任何可以帮助您的东西!
不同的文件介于三行注释和大量空格之间。
// Setmute.js
//
//
module.exports = {
name: 'setmute',description: 'Mutes a user.',aliases: ['setmuterole','muterole'],usage: 'mention reason',cooldown: 5,execute(message,args,user) {
const db = require('quick.db');
let member = message.guild.member(message.member);
if (message.mentions.channels.first()) {
if (message.member.hasPermission('MANAGE_GUILD')) {
db.set(`${member.guild.id}-muterole`,message.mentions.roles.first().id);
console.log(message.mentions.roles.first());
} else if (!message.member.hasPermission('MANAGE_GUILD')) {
return message.reply('you must have \"Manage Guild\" permmissions to access this command,sorry!');
}
};
}
}
// printmute.js
//
//
module.exports = {
name: 'printmute',aliases: ['printmuterole'],user) {
const db = require('quick.db');
let member = message.guild.member(message.member);
let role = db.get(`${member.guild.id}-muterole`);
if (!role) return message.reply("You never set a role.");
console.log(role);
}
}
// Index.js
//
//
const fs = require('fs');
const Discord = require('discord.js');
const db = require('quick.db');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name,command);
}
const cooldowns = new Discord.Collection();
client.once('ready',() => {
console.log('Ready!');
});
client.on('message',message => {
let member = message.guild.member(message.member);
let prefix = db.get(`${member.guild.id}-prefix`);
if (!prefix) prefix = '?';
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
const user = message.mentions.users.first();
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command.guildOnly && message.channel.type !== 'text') {
return message.reply('I can\'t execute that command inside DMs!');
}
if (command.args && !args.length) {
let reply = `You didn't provide any arguments,${message.author}!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
}
return message.channel.send(reply);
}
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name,new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000;
if (timestamps.has(message.author.id)) {
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
}
}
timestamps.set(message.author.id,now);
setTimeout(() => timestamps.delete(message.author.id),cooldownAmount);
try {
command.execute(message,user);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
//client.login(nope,no token here! have a great time,try searching somewhere else!);
当我运行setmute命令(当然,提到一个角色)时,然后我运行printmute时,它会显示“您从未设置过角色。”,即在行会中未设置角色时表示。