Discord.js Commando Broadcast All命令错误



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

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
};
})
}
};

我的问题是,它给了我一个使用它的错误。这就是错误:

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服务器所需要的。

我在Node 12.x上使用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
};
}
};

然而,它给出了这个错误:

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)

我试过的另一件事是:

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
};
}
};

然而,这也失败了。

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

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

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});
});
}

最新更新