Discord.js Commando 广播所有命令错误 [英] Discord.js Commando Broadcast All command error

查看:13
本文介绍了Discord.js Commando 广播所有命令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让广播命令向公会中的所有文本频道发送消息.我当前的代码如下所示:

I'm trying to make broadcast command send a message to all text channels in the guild. My current code looks like this:

const discord = require('discord.js');
const Commando = require('discord.js-commando');

module.exports = class broadcastCommand extends Commando.Command {
  constructor(client) {
    super(client, {
      name: 'broadcast',
      aliases: ['bcast', 'bc'],
      group: 'ebs',
      memberName: 'broadcast',
      userPermissions: ['MANAGE_MESSAGES'],
      description: 'Sends an emergency broadcast to the emergency brodcast channel',
      examples: ['bc ALERT! SUSPICIOUS ENTITY SPOTTED IN DELTA QUADRANT SECTOR B-3! ALL PERSONEL PROCEED WITH CAUTION!'],
      args: [
        {
          key: 'text',
          prompt: 'What would you like to broadcast?',
          type: 'string',
        },
      ],
    })
  };

  run(msg, { text }) {

    let channel = msg.guild.channels.forEarch(channel => {
      if (channel.type === 'text') channel.send(`${text}`); {
        tts: true
      };
    })
  }
};

我的问题是它在使用它时给了我一个错误.这是错误:

My issue is that it gives me a error on using it. This is the error:

11|EBS     |     at CommandoClient.emit (events.js:314:20)
11|EBS     |     at GuildMemberRemoveAction.handle (/home/nimbi/ebs/node_modules/discord.js/src/client/actions/GuildMemberRemove.js:20:62)
11|EBS     |     at GuildMemberRemoveHandler.handle (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/packets/handlers/GuildMemberRemove.js:9:38)
11|EBS     |     at WebSocketPacketManager.handle (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:108:65)
11|EBS     |     at WebSocketConnection.onPacket (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:336:35)
11|EBS     |     at WebSocketConnection.onMessage (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:299:17)
11|EBS     |     at WebSocket.onMessage (/home/nimbi/ebs/node_modules/ws/lib/event-target.js:120:16)
11|EBS     |     at WebSocket.emit (events.js:314:20)
11|EBS     |     at Receiver.receiverOnMessage (/home/nimbi/ebs/node_modules/ws/lib/websocket.js:789:20)
11|EBS     | /home/nimbi/ebs/EBS.sh: line 1: !#/bin/sh: No such file or directory
11|EBS     | (node:28491) DeprecationWarning: Collection#filterArray: use Collection#filter instead
11|EBS     | (Use `node --trace-deprecation ...` to show where the warning was created)
11|EBS     | /home/nimbi/ebs/EBS.sh: line 1: !#/bin/sh: No such file or directory
11|EBS     | (node:22022) DeprecationWarning: Collection#filterArray: use Collection#filter instead
11|EBS     | (Use `node --trace-deprecation ...` to show where the warning was created)

我正在尝试弄清楚如何实现这一点.我正在帮助朋友构建的 SciFi LARP 服务器需要它.

I'm trying to figure out how to implement this. It's needed for a SciFi LARP server that I'm helping a friend build.

我在 Node 12.x 上并使用 Discord.JS Commando

I'm on Node 12.x and using Discord.JS Commando

我也试过这个:

const discord = require('discord.js');
const Commando = require('discord.js-commando');

module.exports = class broadcastCommand extends Commando.Command {
  constructor(client) {
    super(client, {
      name: 'broadcast',
      aliases: ['ebcast', 'bcast', 'bc', 'ebc'],
      group: 'ebs',
      memberName: 'broadcast',
      userPermissions: ['MANAGE_MESSAGES'],
      description: 'Sends an emergency broadcast to the emergency brodcast channel',
      examples: ['bc ALERT! SUSPICIOUS ENTITY SPOTTED IN DELTA QUADRANT SECTOR B-3! ALL PERSONEL PROCEED WITH CAUTION!'],
      args: [
        {
          key: 'text',
          prompt: 'What would you like to broadcast?',
          type: 'string',
        },
      ],
    })
  };

  run(msg, { text }) {

    const channels = msg.guild.channels.filter(c => c.guild && c.type === 'text');
    Promise.all(channels.map(c => c.send(`${text}`))); {
      tts: true
    };
  }
};

但是它给出了这个错误:

However it gave this error:

11|EBS     |     at WebSocketPacketManager.handle (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:108:65)
11|EBS     |     at WebSocketConnection.onPacket (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:336:35)
11|EBS     |     at WebSocketConnection.onMessage (/home/nimbi/ebs/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:299:17)
11|EBS     |     at WebSocket.onMessage (/home/nimbi/ebs/node_modules/ws/lib/event-target.js:120:16)
11|EBS     |     at WebSocket.emit (events.js:314:20)
11|EBS     |     at Receiver.receiverOnMessage (/home/nimbi/ebs/node_modules/ws/lib/websocket.js:789:20)
11|EBS     | /home/nimbi/ebs/EBS.sh: line 1: !#/bin/sh: No such file or directory
11|EBS     | (node:28491) DeprecationWarning: Collection#filterArray: use Collection#filter instead
11|EBS     | (Use `node --trace-deprecation ...` to show where the warning was created)
11|EBS     | /home/nimbi/ebs/EBS.sh: line 1: !#/bin/sh: No such file or directory
11|EBS     | (node:22022) DeprecationWarning: Collection#filterArray: use Collection#filter instead
11|EBS     | (Use `node --trace-deprecation ...` to show where the warning was created)
11|EBS     | /home/nimbi/ebs/EBS.sh: line 1: !#/bin/sh: No such file or directory
11|EBS     | (node:22853) DeprecationWarning: Collection#filterArray: use Collection#filter instead
11|EBS     | (Use `node --trace-deprecation ...` to show where the warning was created)

我尝试过的另一件事是:

Another thing I've tried is this:

const discord = require('discord.js');
const Commando = require('discord.js-commando');

module.exports = class broadcastCommand extends Commando.Command {
  constructor(client) {
    super(client, {
      name: 'broadcast',
      aliases: ['ebcast', 'bcast', 'bc', 'ebc'],
      group: 'ebs',
      memberName: 'broadcast',
      userPermissions: ['MANAGE_MESSAGES'],
      description: 'Sends an emergency broadcast to the emergency brodcast channel',
      examples: ['bc ALERT! SUSPICIOUS ENTITY SPOTTED IN DELTA QUADRANT SECTOR B-3! ALL PERSONEL PROCEED WITH CAUTION!'],
      args: [
        {
          key: 'text',
          prompt: 'What would you like to broadcast?',
          type: 'string',
        },
      ],
    })
  };

  run(msg, { text }) {

    const channel_list = msg.guild.channels.find(c => c.id ===  ['759042556972630036', '759042556972630037', '759042556972630038', '759061573867405312', '759042556536553557', '759801988560322611', '759116305218666496'])

 
    return channel_list.send(`${ text }`); {
      tts: true
    };
  }
};

然而那也失败了.

推荐答案

你走在正确的轨道上.最大的问题是你定义了 MessageOptions.send 函数之外.

You're reasonably on the right track. The biggest issue is that you define the MessageOptions outside of the .send function.

检查下面的代码示例并尝试一下.

Check the code example below and give it a try.

run(msg, { text}) {
  // Note if you're using Discord JS version 12.0.0 or higher, you need to use '.channels.cache'
  // If you're using Discord JS version 11.1.0 or lower, remove the '.cache'
  msg.guild.channels.cache
    .filter(channel => channel.type === 'text')
    .forEach((textChannel) => {
      textChannel.send(text, {tts: true});
    });
}

这篇关于Discord.js Commando 广播所有命令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆