簡體   English   中英

Unban 命令 Discord.js V12

[英]Unban Command Discord.js V12

我使用 discord.js v12 做了一個 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);
  }
};

正如我之前提到的,當我運行命令時出現錯誤。 這是我得到的錯誤:

(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.

我無法理解如何解決這個問題。 你能幫我嗎? 提前致謝!

運行命令時,必須確保 index.js 使用正確的參數執行命令:

索引.js

command.run(message, args)

不是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM