我从参数中删除特定的不和谐频道时遇到问题

时间:2019-10-02 18:03:33

标签: javascript discord

我已经为我的discord机器人编写了一个快速通道删除命令,但是只有在我不包含#的情况下,它才有效,有没有办法甚至使用#标签将其删除?

我尝试将#添加到args.join(' ')上,但还是没有运气。

我写的代码是:

exports.run = (client, message, args) => {
let channel = args.slice(0).join(" ");
const fetchedChannel = message.guild.channels.find(c => c.name === args.join(' '));
  message.delete(5000)
  if (!args.length) {
    return message.channel.send(`Invalid Channel, ${message.author}!`);
    message.delete(5000)
  }
let embed1 = new Discord.RichEmbed()
.setTitle("Deleting Channel")
.setDescription(`Deleting Channel: ${fetchedChannel}`)
.setColor([255, 0, 0])
.addField(`Command ran by:`, `${message.author.username}`)
.setTimestamp(message.createdAt)
message.channel.send({embed: embed1})
message.channel.send("Deleting Channel Please Wait 15 Seconds.").then(fetchedChannel.delete(5000))
};

const Discord = require('discord.js');
const client = new Discord.Client(); // This uses the discord.js package to setup a client



exports.conf = {
  enabled: true,
  guildOnly: false,
  aliases: [],
  permLevel: "Admin"
};


exports.help = {
  name: "delc",
  category: "System",
  description: "Delete a channel",
  usage: "delc <channelname>"
};

我希望结果将使用#ex:#TextChannel而不是TextChannel删除指定的通道,但是我收到的错误是:

[2019-10-02 12:55:06]: READY [READY] FiveM Community Ready Bot#1040, ready to serve 22625 users in 77 servers.
[2019-10-02 13:01:30]: CMD [CMD] Patrol Announcer Rhys19 (*****************) ran command delc
[2019-10-02 13:01:30]: ERROR Uncaught Exception: TypeError: Cannot read property 'delete' of null
    at Object.exports.run (C:\Users\Rhys19\Desktop\FCRB\commands\delc.js:19:86)
    at module.exports (C:\Users\Rhys19\Desktop\FCRB\events\message.js:61:7)
    at Client.emit (events.js:189:13)
    at MessageCreateHandler.handle (C:\Users\Rhys19\Desktop\FCRB\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Rhys19\Desktop\FCRB\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (C:\Users\Rhys19\Desktop\FCRB\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Rhys19\Desktop\FCRB\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Rhys19\Desktop\FCRB\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:189:13)
    at Receiver._receiver.onmessage (C:\Users\Rhys19\Desktop\FCRB\node_modules\ws\lib\websocket.js:137:47)
PS C:\Users\Rhys19\Desktop\FCRB>

0 个答案:

没有答案