将嵌入发送到不同的频道 (Discord JS)
Sending an Embed to a different channel (Discord JS)
我正在尝试将嵌入发送到不同的频道,而不是发送到执行命令的频道,但我收到了一个错误 "Cannot access 'bot' before initialization" 我不知道我做错了什么 tbh bc 我已经在index.js.
的顶部
case "alert":
let text = message.content.replace(prefix + "alert", "")
const alertembed = new Discord.MessageEmbed()
.setTitle("**Embed Title**")
.setDescription(text)
bot.channels.find("carts").send(alertembed)
embed.Message.react("")
embed.Message.react("")
const Discord = require("discord.js")
const bot = new Discord.Client();
const ms = require("ms")
const fs = require("fs")
var version = "1.0"
const config = require("./config.json")
let prefix = config.prefix;
const token = config.token;
bot.on("ready", () =>{
console.log("Succesfully started the tools bot");
})
bot.on("message", message=>{
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]){
...
好的,根据您提供的信息,我发现了一些问题,但错误消息不是我所期望的。这些当然是问题,但我不确定这是 的问题。
在 v12 中,大多数集合都被包含名为 cache
的集合的管理器对象所取代。这包括 message.channels。因此,要访问频道缓存集合,您需要使用:
message.channels.cache.find()
但这仍然存在问题,因为使用基于字符串的查找在 v11 中已被弃用并在 v12 中被删除。你必须传递一个 returns true 的函数,如果它是你想要的。
bot.channels.cache.find(ch => ch.name === "carts")
更新:
我注意到的另一件事..
embed.Message.react("")
我没有看到名为 embed 的变量。我认为您的意思是从发送开始执行此操作。
bot.channels.cache.find(ch => ch.name === "carts").send(alertembed).then(sent => {
sent.react("")
sent.react("")
});
我正在尝试将嵌入发送到不同的频道,而不是发送到执行命令的频道,但我收到了一个错误 "Cannot access 'bot' before initialization" 我不知道我做错了什么 tbh bc 我已经在index.js.
的顶部 case "alert":
let text = message.content.replace(prefix + "alert", "")
const alertembed = new Discord.MessageEmbed()
.setTitle("**Embed Title**")
.setDescription(text)
bot.channels.find("carts").send(alertembed)
embed.Message.react("")
embed.Message.react("")
const Discord = require("discord.js")
const bot = new Discord.Client();
const ms = require("ms")
const fs = require("fs")
var version = "1.0"
const config = require("./config.json")
let prefix = config.prefix;
const token = config.token;
bot.on("ready", () =>{
console.log("Succesfully started the tools bot");
})
bot.on("message", message=>{
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]){
...
好的,根据您提供的信息,我发现了一些问题,但错误消息不是我所期望的。这些当然是问题,但我不确定这是 的问题。
在 v12 中,大多数集合都被包含名为 cache
的集合的管理器对象所取代。这包括 message.channels。因此,要访问频道缓存集合,您需要使用:
message.channels.cache.find()
但这仍然存在问题,因为使用基于字符串的查找在 v11 中已被弃用并在 v12 中被删除。你必须传递一个 returns true 的函数,如果它是你想要的。
bot.channels.cache.find(ch => ch.name === "carts")
更新:
我注意到的另一件事..
embed.Message.react("")
我没有看到名为 embed 的变量。我认为您的意思是从发送开始执行此操作。
bot.channels.cache.find(ch => ch.name === "carts").send(alertembed).then(sent => {
sent.react("")
sent.react("")
});