【发布时间】:2019-04-26 03:10:03
【问题描述】:
我在 Reddit 和 StackOverflow 上搜索并发现了多个论坛帖子,其中用户询问如何将消息发送到特定频道,但我找不到可以使用 Argument 发送到特定频道的帖子。我的意思是你使用
return bot.channels.get(channel).send(embed);
我一直在测试这个“功能”,并设法将消息发送到特定的频道,但它还包括 arg[0] 又名频道 ID。命令是
announce "CHANNEL ID" "MESSAGE"
它确实将带有消息的嵌入发送到我输入的特定频道,但是它将CHANNEL ID 添加到嵌入中,所以我尝试在嵌入的.setDescription(arg[0]) 中使用arg[0],但它不起作用。它向我吐出一条错误消息,我不知道这是什么意思。但是,如果您的专业人士在那里知道我能做什么,也许一个。这是整个命令代码:
if (cmd === `${prefix}announce`) {
console.log(message.author.username + " executed an Announcement in the channel #" + message.channel.name);
const embed = new Discord.RichEmbed()
.setColor("#e56b00")
.setAuthor("Announcement from " + message.author.username, message.author.avatarURL)
.setDescription(arg)
.setFooter(message.author.username)
.setTimestamp();
return bot.channels.get(channel).send(embed);
}
这是错误代码。请注意,仅当我将 arg[0] 放入嵌入的 .setDescription() 部分时才会弹出错误。频道让 arg[1] 正常工作
(node:7900) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
at Client.bot.on (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\index.js:32:34)
at Client.emit (events.js:182:13)
at MessageCreateHandler.handle (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:182:13)
at Receiver._receiver.onmessage (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\ws\lib\websocket.js:137:47)
at Receiver.dataMessage (C:\Users\Admin\Desktop\Discord Bots\DISCORDBOSS.js\node_modules\ws\lib\receiver.js:409:14)
(node:7900) 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(). (rejection id: 1)
(node:7900) [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.
【问题讨论】:
-
我试过了,不让我使用代码格式。它只是被窃听了。谢谢我还需要补充:pastebin.com/SKfe2f9g
-
谢谢你,乔治
标签: javascript bots discord discord.js