每当我对嵌入做出反应时,它都会发送两次消息。 [DiscordAPIError:未知消息]

时间:2020-08-25 22:29:14

标签: javascript discord.js

我有一个waifu命令,它获取图像和名称并将其放在嵌入中,然后还与?表情符号反应。我想做到这一点,以便第一个点击表情符号的人会要求使用waifu。

PYTHONHOME

它可以工作,但是例如,如果我做/ waifu,它发送嵌入并说(waifuname)已声明,但是每当我再次做/ waifu时,一切都一样,但是当我单击react按钮时,它说声称以前和现在的waifu。 https://aws1.discourse-cdn.com/business6/uploads/glitch/original/2X/9/98363d9496747899fe23698cb0f98846b1e7136c.jpeg

(Umaru Doma是我上次发布的waifu)

它也给出一个错误: const { Client, MessageEmbed, ReactionCollector} = require('discord.js'); const { prefix } = require('../../config'); const superagent = require('superagent'); const { urlencoded } = require('body-parser'); module.exports = { name: 'waifu', category: 'waifu', description: 'Random Waifu', usage: `${prefix}waifu`, perms: 'Send Messages', cooldown: 5, run: async (bot, message, args) => { const rating1 = 10 const rating2 = Math.floor(Math.random() * rating1) var rating = rating2 const decimals1 = 100 const decimals2 = Math.floor(Math.random() * decimals1) var decimals = decimals2 const compatibility1 = 100 const compatibility2 = Math.floor(Math.random() * compatibility1) var compatibility = compatibility2 const { waifuID } = require("../../Database/WaifuNameDB.json") let randW = Math.floor(Math.random() * Object.keys(waifuID).length) let randomWaifu = waifuID[randW] let embed2 = new MessageEmbed() .setTitle(`?${randomWaifu.names}?`) .addField("Claims:", `${randomWaifu.claims}`) .addField("Rating:", `${rating}.${decimals}/10 ⭐`) .setImage(`${randomWaifu.img_url}`, innerHeight = '500', innerWidth = '500') .setColor('#f095d1') .setFooter(`| Powered by: @Twintails? API `, `https://64.media.tumblr.com/1a1c3bcc08b5a048b90139a56fe7f415/tumblr_o9ku1rVS8z1vnqjx7o2_250.png`) var mg = await message.channel.send(embed2); mg.react('?') message.delete() bot.on('messageReactionAdd', async (reaction, user) => { if (reaction.mg) await reaction.mg.fetch(); if (reaction) await reaction.fetch() if (user.bot) return; if (reaction.emoji.name == "?") { message.channel.send(`${randomWaifu.names} was claimed!`) mg.delete() if(user = message.author) return; } }) } }

请帮助!

1 个答案:

答案 0 :(得分:0)

我已经找到一种解决每个人的方法!

bot.on('messageReactionAdd', (messageReaction, user) => {
            
            if(user.bot) return;
            const {
                message,
                emoji
            } = messageReaction;

            if (emoji.name === "?") {
                if (!message.id === mg.id) return;
                if (message.id === mg.id) {

                    mg.delete()
                    message.channel.send(`${randomWaifu.names} was claimed!`)
                }
            }
        });