如何修复Discord API:未知消息错误?

时间:2019-12-30 19:49:25

标签: javascript discord

我试图发出一个meme命令,但是每当我尝试使用它时,都会出现此错误“ DiscordAPIError:未知消息”。

这是较早的工作,但是当我回到PC时,它开始出现故障。

这是我的代码

const { RichEmbed } = require("discord.js");
const randomPuppy = require("random-puppy");
const usedCommandRecently = new Set();

module.exports = {
    name: "meme",
    aliases: ["memes", "reddit"],
    category: "fun",
    description: "Sends a random meme",
    run: async (client, message, args) => {
        if (message.deletable) message.delete();
        var Channel = message.channel.name
        //Check it's in the right channel
        if(Channel != "memes") {
            const channelembed = new RichEmbed()
                .setColor("BLUE")
                .setTitle(`Use me in #memes`)
                .setDescription(`Sorry ${message.author.username} this command is only usable in #memes !`)
            return message.channel.send(channelembed);
        }
        //Check cooldown
        if(usedCommandRecently.has(message.author.id)){
            const cooldownembed = new RichEmbed()
                .setColor("GREEN")
                .setTitle("Slow it down, pal")
                .setDescription(`Sorry ${message.author.username} this command has a 30 second cooldown per member, sorry for any inconvenice this may cause`)
            message.channel.send(cooldownembed)
        } else{
            //Post meme
            const subReddits = ["dankmeme", "meme", "me_irl"];
            const random = subReddits[Math.floor(Math.random() * subReddits.length)];

            const img = await randomPuppy(random);
            const embed = new RichEmbed()
                .setColor("RANDOM")
                .setImage(img)
                .setTitle(`From /r/${random}`)
                .setURL(`https://reddit.com/r/${random}`);

            message.channel.send(embed);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

不确定,但是您的require块可能有问题。 const { RichEmbed } = require("discord.js");

正确的方法:

const Discord = require("discord.js");
let cooldownembed  = new Discord.RichEmbed();

以及为什么在此处使用返回

return message.channel.send(channelembed);