将嵌入发送到其他频道(Discord JS)

时间:2020-04-16 16:17:32

标签: javascript discord embed discord.js

我正在尝试将嵌入内容发送到其他通道,而不是发送到执行命令的通道,但是出现错误“初始化前无法访问'bot'”我不知道自己做错了什么tbh bc ive声明了所有内容在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]){
...

1 个答案:

答案 0 :(得分:0)

好的,根据您提供的信息,我看到了一些问题,但是错误消息并不是我期望的。这些当然是问题,但是我不确定这是 问题。

在v12中,大多数集合由包含名为cache的集合的管理器对象代替。这包括message.channels。因此,要访问通道缓存集合,您需要使用:

message.channels.cache.find()

但是,这仍然存在问题,因为在v11中不建议使用基于字符串的find,而在v12中已将其删除。如果需要,您必须传递一个返回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("?")
});
相关问题