[英]Discord.js bot ban command not send message. discord.js 11.6.2
I'm Spanish so my English might be a little rusty.我是西班牙人,所以我的英语可能有点生疏。 I have a discord bot with a command that ban a member and sends him a message with the server that has been banned, reasons, etc. But a few days ago I realized that my bot did not send the message, but I have not changed the code since the last stable release, where the bot sent the message to the banned.
我有一个discord bot,有一个禁止成员的命令,并向他发送一条消息,其中包含已被禁止的服务器、原因等。但前几天我意识到我的bot没有发送消息,但我没有改变自上次稳定版本以来的代码,其中机器人将消息发送给被禁止的人。 When I delete the line that ban the user (
message.guild.ban(mentioned, {reason: reason});
) the bot sends the message without any error.当我删除禁止用户的行(
message.guild.ban(mentioned, {reason: reason});
)时,机器人会发送消息而没有任何错误。 You have below the command code , and here you have the error that displays the command prompt.你有下面的命令代码,在这里你有显示命令提示符的错误。
module.exports = {
name: 'condenar',
description: "Comando principal del verdugo que avisa al condenado. Se suele usar antes del v!ban",
execute(message, args){
if (message.member.roles.find("name", "Monarca")){
const Discord = require('discord.js');
var embedColor = '#ff0000'
const moment = require("moment");
var missingPermissionsEmbed = new Discord.RichEmbed()
.setColor(embedColor)
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Permisos insuficientes!')
.setDescription('Necesitas el permiso `MANAGE_MESSAGES` para usar este comando!')
.setTimestamp();
var missingArgsEmbed = new Discord.RichEmbed()
.setColor(embedColor)
.setAuthor(message.author.username, message.author.avatarURL)
.setTitle('Argumentos insuficientes!')
.setDescription('Uso: v!condenar <@User> <Motivo>')
.setTimestamp();
if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send(missingPermissionsEmbed);
let mentioned = message.mentions.users.first();
if (mentioned.id == 615199347398672392) return message.channel.send('No ahorcare a mi padre.');
if(!mentioned) return message.channel.send(missingArgsEmbed);
let reason = args.slice(1).join(' ')
if(!reason) return message.channe.send(missingArgsEmbed);
var ahorcNumber = Math.random();
var ahorcEmbed = new Discord.RichEmbed()
.setColor(embedColor)
.setDescription(`ID del mensaje: ${message.id}`)
.setTitle(`**Ahorcamiento ${message.guild.name}**`)
.addField('Ahorcado por:', message.author.tag)
.addField('Motivo:', reason)
.addField('ID del ahorcamiento:', `**${ahorcNumber}** *necesitaras este numero para ver la info del ahorcamiento mas adelante.`)
.attachFiles(['./img/ahorcado.gif'])
.setFooter(`En: ${moment().format("dddd, MMMM Do YYYY, h:mm A", Date.now())}`)
.setTimestamp();
mentioned.send(ahorcEmbed);
message.channel.send(ahorcEmbed);
message.guild.ban(mentioned, {reason: reason});
var dir = `./files/${message.guild.id}`;
var fs = require('fs');
if (!fs.existsSync(dir)){
fs.mkdirSync(dir, function(err, result) {
if(err) console.log('error', err);
});
fs.mkdirSync(`${dir}/warns`, function(err, result) {
if(err) console.log('error', err);
});
fs.mkdirSync(`${dir}/ahorcamientos`, function(err, result) {
if(err) console.log('error', err);
});
};
fs.mkdirSync(`${dir}/ahorcamientos/${ahorcNumber}`);
fs.writeFile(`${dir}/ahorcamientos/${ahorcNumber}/ahorcado.txt`, `${mentioned.username}(${mentioned.id})`, 'utf8', function(err, result) {
if(err) console.log('error', err);
});
fs.writeFile(`${dir}/ahorcamientos/${ahorcNumber}/Author.txt`, `${message.author.username}(${message.author.id})`, 'utf8', function(err, result) {
if(err) console.log('error', err);
});
fs.writeFile(`${dir}/ahorcamientos/${ahorcNumber}/Motivo.txt`, `${reason}`, 'utf8', function(err, result) {
if(err) console.log('error', err);
});
if (!fs.existsSync(`${dir}/ahorcamientos/${mentioned.id}.txt`)){
fs.writeFile(`${dir}/ahorcamientos/${mentioned.id}.txt`, 1, 'utf8', function(err, result) {
if(err) console.log('error', err);
});
}else{
fs.readFile(`${dir}/ahorcamientos/${mentioned.id}.txt`, 'utf8', function(err, data) {
var x = +data;
var y = 1;
var z = x + y;
fs.writeFile(`${dir}/ahorcamientos/${mentioned.id}.txt`, `${z}`, 'utf8', function(err, result) {
if(err) console.log('error', err);
});
});
};
}else{
message.channel.send('Tienes que tener el rol `Monarca` para poder usar este comando');
};
}};
The answer is quite simple, users may not be allowed to send messages to them in DM :)答案很简单,可能不允许用户在 DM 中向他们发送消息 :)
And you has error here, missing n
in channel
:你在这里有错误,在
channel
缺少n
:
return message.channe.send(missingArgsEmbed);
Was a problem with the confidentiality settings of my testing account.我的测试帐户的机密性设置有问题。 Thanks to everyone.
谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.