我在discord.js v12中发出了ban命令。但是,每当我运行命令时,都会出现错误。这是我的代码:
const Discord = require('discord.js');
module.exports = {
name: "ban",
description: "Kicks a member from the server",
async run (client, message, args) {
if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send('You can\'t use that!')
if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send('I don\'t have the right permissions.')
const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
if(!args[0]) return message.channel.send('Please specify a user');
if(!member) return message.channel.send('Can\'t seem to find this user. Sorry \'bout that :/');
if(!member.bannable) return message.channel.send('This user can\'t be banned. It is either because they are a mod/admin, or their highest role is higher than mine');
if(member.id === message.author.id) return message.channel.send('Bruh, you can\'t ban yourself!');
let reason = args.slice(1).join(" ");
if(!reason) reason = 'Unspecified';
member.ban(`${reason}`).catch(err => {
message.channel.send('Something went wrong')
console.log(err)
})
const banembed = new Discord.MessageEmbed()
.setTitle('Member Banned')
.setThumbnail(member.user.displayAvatarURL())
.addField('User Banned', member)
.addField('Kicked by', message.author)
.addField('Reason', reason)
.setFooter('Time kicked', client.user.displayAvatarURL())
.setTimestamp()
message.channel.send(banembed);
}
}
正如我之前提到的,每当我运行代码时,我都会不断收到错误消息。对编码有点陌生,我无法自己解决问题。这是我收到的错误:
Response: Internal Server Error
at RequestHandler.execute (/home/runner/Utki-the-bot/node_modules/discord.js/src/rest/RequestHandler.js:158:11)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 500,
method: 'put',
path: '/guilds/751424392420130907/bans/155149108183695360'
}
你能帮帮我吗?预先感谢!
答案 0 :(得分:1)
错误不是你的。错误可能是由 Discord 服务器或 discord.js 引起的。你可以等它解决了。也许几分钟。
答案 1 :(得分:0)
我想向你展示我是如何在 discord.js v12 中制作禁止和临时禁止命令的
希望这段代码能帮到你,感谢阅读
const reasonBan = msg.slice(3)
const msg = message.content.split(" ")
const args = msg.slice(1)
if (cmd === "bt!ban")
{
const person = message.mentions.users.first()
if(message.member.hasPermission("ADMINISTRATOR") || message.member.hasPermission("BAN_MEMBERS"))
{
if(args.length === 0)
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**Tienes que especificar dar los argumentos del comando de la siguiente manera:**
\`bt!ban <usuario> <tiempo> <razón> \` `)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
else
{
if(!person)
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, tienes que mencionar a alguien a quién banear.**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
else
{
if(person.id === message.author.id)
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, No puedes banearte a ti mismo**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
else if(person.id === message.guild.me.id)
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, No puedes banearme a mi. >:c**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
else
{
const isBannable = message.guild.member(person)
if(isBannable.bannable)
{
try
{
isBannable.ban(
{
reason:
reasonBan.length === 0 ?
"Razón no espeficada":
reasonBan.join(" ")
})
.then(() =>
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, el usuario ${person}, ha sido baneado correctamente.**
**Razón : ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}**
**Tiempo: ${args[1]}**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed).then(() =>
{
setTimeout(() => {
try
{
message.guild.fetchBans().then( bans =>
{
message.guild.members.unban(person)
})
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, el usuario ${person}, ha sido desbaneado correctamente.
**Razón : ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}
Tiempo: ${args[1]}**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
catch (err)
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, Ha ocurrido un error al intentar quitar el ban de ${person}.**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
}, ms(args[1]))
})
})
}
catch (error)
{
isBannable.ban(
{
reason:
reasonBan.length === 0 ?
"Razón no espeficada":
reasonBan.join(" ")
}
)
.then(() =>
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, el usuario ${person}, ha sido baneado correctamente.**
**Razón: ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
})
}
}
else
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`**${message.author}, el usuario tiene más permisos que yo o no está en el server.**`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
}
}
}
}
else
{
embed
.setAuthor("BAN COMMAND" , client.user.avatarURL())
.setDescription(`${message.author} ,No tienes permisos para ejecutar este comando.`)
.setColor("RANDOM")
.setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
return message.channel.send(embed)
}
}