【发布时间】:2021-11-21 09:39:37
【问题描述】:
当我使用命令踢但我的机器人没有响应时,我想让 gif 反应随机发送,终端也没有错误。
kick.js 文件:
const Discord = require('discord.js');
const fs = require('fs');
module.exports = {
name: 'kick',
description: 'Kicks A User.',
execute(message, args) {
const { Permissions } = require('discord.js');
let randomNumber = (Math.floor(Math.random() * 12) + 1);
const member = message.mentions.members.first();
fs.readdir('./kickgifs', (err, files) => {
if(err) return console.log(err);
let embed = new Discord.MessageEmbed()
.setColor(000000)
.setImage(`${randomNumber}.gif`)
if (!member) return message.channel.send("Invalid Member Given!");
if (member.roles.highest.position > message.member.roles.highest.positon) return message.channel.send("This user is a higher role than you!");
let reason = args.slice(1).join(" ");
if (!reason) reason = "No Reason Provided!";
member.kick()
.catch(console.log)
message.channel.send({ embeds: [embed.setDescription(`<@${member.user.id}> Has Been **Kicked** By **${message.author.username}**`)] })
});
}
}
index.js 文件:
const { Intents, Client, MessageEmbed, Attachment, DiscordAPIError, Collection } = require('discord.js'); // require other classes as per your bot needs
const intents = [Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]; // Add other related intents
const client = new Client({ intents: intents });
const prefix = '!';
var version = '1.0.1';
const targetChannelId = '799206261978693634' // Channel for rules
const welcomeChannelId = '798928691988004897' // Channel for welcome message
const fs = require('fs');
client.commands = new 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);
}
client.once('ready', () => {
console.log('Baji is online.');
setInterval(() => {
const statuses = [
`!help | ♡`,
`Your Home`,
]
const status = statuses[Math.floor(Math.random() * statuses.length)]
client.user.setActivity(status, { type: "WATCHING" }) // Can Be WATCHING, STREAMING, LISTENING
}, 2000) // Second You Want to Change Status, This Cahnges Every 2 Seconds
});
client.on('guildMemberAdd', (member) => {
console.log(member)
const channel = member.guild.channels.cache.get(welcomeChannelId)
const embed = new MessageEmbed()
.setColor('#000000')
.setTitle(`Welcome To ${member.guild.name}`)
.setDescription(`Hello <@${member.user.id}> Make sure to check out the ${member.guild.channels.cache.get(targetChannelId).toString()} in order to keep this server nice and safe! We hope you enjoy your stay!`)
.setThumbnail(member.user.displayAvatarURL({ dynamic: true, size: 512 }))
.setFooter(`From the love of ${member.guild.name}`)
channel.send({ embeds: [embed] });
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
client.commands.get('ping').execute(message, args);
} else if (command == 'website') {
client.commands.get('website').execute(message, args);
} else if (command == 'clear') {
client.commands.get('clear').execute(message, args);
} else if (command == 'kick') {
client.commands.get('kick').execute(message, args);
} else if (command == 'ban') {
client.commands.get('ban').execute(message, args);
}
switch (args[0]) {
case 'profile':
const embed = new MessageEmbed()
.setTitle('User Information')
.addField('User Name', message.author.username)
.addField('Version ', version)
.addField('Current Server', message.guild.name)
.setColor(000000)
.setFooter('jajaja')
.setThumbnail(message.author.displayAvatarURL())
message.channel.send({ embeds: [embed] });
break;
case 'hello':
const embed1 = new MessageEmbed()
.setDescription(`<@${member.user.id}> is greeting Everone!`)
.setColor(000000)
message.channel.send({ embeds: [embed1] });
break;
case 'info':
if (args[1] === 'version') {
message.channel.send('Version ' + version);
} else {
message.channel.send('Invalid Args')
}
break;
}
})
client.login('TOKEN');
此外,profile、info 和 hello 命令也不起作用。
【问题讨论】:
-
这是你的处理程序的问题,你需要调试
-
它是踢起来不说什么,还是什么都不做?
-
是的,什么都不做
标签: javascript node.js visual-studio-code discord.js