Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Unban命令Discord.js V12_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript Unban命令Discord.js V12

Javascript Unban命令Discord.js V12,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我使用discord.jsv12发出了一个unban命令。每当我运行命令时,都会出现一个错误。我对编码有点陌生,我自己无法解决这个错误。以下是unban命令的代码: const { MessageEmbed } = require('discord.js'); const rgx = /^(?:<@!?)?(\d+)>?$/; module.exports = { name: "unban", description: "Unbans

我使用discord.jsv12发出了一个unban命令。每当我运行命令时,都会出现一个错误。我对编码有点陌生,我自己无法解决这个错误。以下是unban命令的代码:

const { MessageEmbed } = require('discord.js');

const rgx = /^(?:<@!?)?(\d+)>?$/;

module.exports = {
    name: "unban",
    description: "Unbans a member from the server",

  async run(message, args) {
    const id = args[0];
    if (!rgx.test(id)) return message.channel.send('Please provide a valid user ID');
    const bannedUsers = await message.guild.fetchBans();
    const user = bannedUsers.get(id).user;
    if (!user) return message.channel.send('Unable to find user, please check the provided ID');

    let reason = args.slice(1).join(' ');
    if (!reason) reason = '`None`';
    if (reason.length > 1024) reason = reason.slice(0, 1021) + '...';

    await message.guild.members.unban(user, reason);
    const embed = new MessageEmbed()
      .setTitle('Unban Member')
      .setDescription(`${user.tag} was successfully unbanned.`)
      .addField('Moderator', message.member, true)
      .addField('Member', user.tag, true)
      .addField('Reason', reason)
      .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(message.guild.me.displayHexColor);

    message.channel.send(embed);
  }
};
const{MessageEmbed}=require('discord.js');
常数rgx=/^(?:?$/;
module.exports={
名称:“unban”,
description:“从服务器取消绑定成员”,
异步运行(消息,参数){
常量id=args[0];
if(!rgx.test(id))返回message.channel.send('请提供有效的用户id');
const bannedUsers=wait message.guild.fetchBans();
const user=bannedUsers.get(id).user;
if(!user)返回message.channel.send('找不到用户,请检查提供的ID');
让reason=args.slice(1.join)(“”);
如果(!reason)reason=`None`;
如果(reason.length>1024)reason=reason.slice(01021)+’…”;
等待消息.guild.members.unban(用户,原因);
const embed=new MessageEmbed()
.setTitle(“Unban成员”)
.setDescription(`${user.tag}已成功取消绑定。`)
.addField('主持人',message.member,true)
.addField('Member',user.tag,true)
.addField('原因',原因)
.setFooter(message.member.displayName,message.author.displayAvatarURL({dynamic:true}))
.setTimestamp()文件
.setColor(message.guild.me.displayHexColor);
message.channel.send(嵌入);
}
};
正如我前面提到的,我在运行命令时遇到一个错误。下面是我遇到的错误:

(node:310) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
    at Object.run (/home/runner/Utki-the-bot/commands/unban.js:11:47)
    at Client.<anonymous> (/home/runner/Utki-the-bot/index.js:71:42)
    at Client.emit (events.js:315:20)
    at Client.EventEmitter.emit (domain.js:483:12)
    at MessageCreateAction.handle (/home/runner/Utki-the-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/home/runner/Utki-the-bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/home/runner/Utki-the-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/runner/Utki-the-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/runner/Utki-the-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/runner/Utki-the-bot/node_modules/ws/lib/event-target.js:125:16)
(node:310) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:310) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(节点:310)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“send”
在Object.run(/home/runner/Utki-the-bot/commands/unban.js:11:47)
在客户端。(/home/runner/Utki-the-bot/index.js:71:42)
在Client.emit(events.js:315:20)
位于Client.EventEmitter.emit(domain.js:483:12)
在MessageCreateAction.handle(/home/runner/Utki-the-bot/node_-modules/discord.js/src/client/actions/MessageCreate.js:31:14)
在Object.module.exports[作为MESSAGE_CREATE](/home/runner/Utki bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
在WebSocketManager.handlePacket(/home/runner/Utki-the-bot/node_-modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
在WebSocketShard.onPacket(/home/runner/Utki-the-bot/node_-modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
在WebSocketShard.onMessage(/home/runner/Utki-the-bot/node_-modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
在WebSocket.onMessage(/home/runner/Utki-the-bot/node_-modules/ws/lib/event-target.js:125:16)
(节点:310)UnhandledPromisejectionWarning:Unhandled Promisejection拒绝。此错误源于在没有catch块的异步函数内部抛出,或拒绝未使用.catch()处理的承诺。若要在未处理的承诺拒绝时终止节点进程,请使用CLI标志“---Unhandled rejections=strict”(见https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)(拒绝id:1)
(node:310)[DEP0018]弃用警告:未处理的承诺拒绝将弃用。将来,未处理的承诺拒绝将使用非零退出代码终止node.js进程。

我不明白如何解决这个问题。你能帮我吗?提前谢谢!

运行命令时,必须确保index.js使用正确的参数执行命令:

index.js

command.run(message, args)
不是这样的:

command.run(args, message) // Or something like that

无论
message
是什么,它都没有
channel
属性到
console.log(message)
查看
消息
的实际内容。错误表明您的
消息
对象没有
发送
属性。我添加了它,但仍然得到相同的错误@wgumenyuk是否使用Commando?否@김현진 我不使用突击队