【问题标题】:How to fix Discord API: Unknown Message error?如何修复 Discord API:未知消息错误?
【发布时间】:2019-12-31 06:33:40
【问题描述】:

我正在尝试制作 meme 命令,但每当我尝试使用它时,我都会收到此错误“DiscordAPIError: Unknown Message”。

这在之前可以正常工作,但是当我回到我的电脑时它开始出现故障。

这是我的代码

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

【问题讨论】:

  • 您是否尝试将console.log() 添加到您的代码中?就像记录一个步骤过程并找出导致问题的消息块?我觉得没问题。

标签: javascript discord


【解决方案1】:

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

正确的方式:

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

以及为什么在这里使用return

return message.channel.send(channelembed);

【讨论】:

  • 感谢修复它。另外,我使用了 return,所以它没有执行其余的代码(发送 meme),所以他们在正确的频道中完成了
猜你喜欢
  • 2020-11-02
  • 2021-06-14
  • 2022-01-05
  • 2021-09-20
  • 2021-12-26
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 2023-03-18
相关资源
最近更新 更多