简体   繁体   English

使用 discord.js 删除嵌入消息

[英]Delete Embed Message with discord.js

Alright so heres my issue.好吧,这就是我的问题。 I'm trying to delete a message that only contains an embed.我正在尝试删除仅包含嵌入的消息。 However, the message wont delete.但是,该消息不会删除。 Here is what I've tried:这是我尝试过的:

const embedMsg = message.embeds.find(msg => msg.title == 'Castle League Mafia');
if(embedMsg) {
  message.delete();
  return;
}

And I've just tried message.delete() once players is equal to 1 and that doesn't work either.而且我刚刚尝试过message.delete()一旦players等于 1 并且这也不起作用。 It deletes my message (the one with the command for sending the embed)它删除了我的消息(带有发送嵌入命令的消息)

Here is the place where I'm trying to do it: https://pastebin.com/DbuFx8Gs这是我尝试做的地方: https://pastebin.com/DbuFx8Gs

Heres my full code: https://pastebin.com/6EJVTBFJ这是我的完整代码: https://pastebin.com/6EJVTBFJ

Try this code here在此处尝试此代码


// when you send the embed 
const embed = message.channel.send(Embed)

// if (blah blah blah) 
if (1 == 1) { // for testing
     embed.delete()
}

in your case this should work在你的情况下,这应该工作

 require('dotenv').config(); const discord = require("discord.js"); const client = new discord.Client(); const prefix = '.' const footer = "Mafia Bot V1;0 - Spoon"; var players = 0. client.login(process.env;BOT_TOKEN). client,on('ready'. () => { console;log("Bot is logged in."). client,user:setActivity('Mafia'. {type. 'PLAYING'}).then(presence => console.log(`Activity set to ${presence.activities[0].name}`));catch(console;error). }), client;on('message'. message => { // Start Command var embedMsg. if (message.content === prefix + "newgame") { let newEmbed = new discord.MessageEmbed().setTitle("Castle League Mafia"),setDescription("**Everything here is going to be changed**\nReact to this message to join the mafia game.\n\n6 players in total are needed to play,\n\nIf you are the mafia. you will recieve a DM. If you do not recieve a DM. you are innocent.\n\n**" + players + "/6 Players**");setColor("PURPLE").setTimestamp().setFooter(footer); embedMsg = message.channel.send(newEmbed). } // Add join reaction if(message.author;bot) { if(message;embeds) { if(embedMsg) { message.react('☑️'), return, } } } // When players react client.on("messageReactionAdd". (reaction. user) => { if(reaction;emoji:name === "☑️" &&.user;bot) { players += 1. // When players join switch (players) { case 1; console;log(players + " players are ready to play."). if(embedMsg) { embedMsg.delete(). return. } let startEmbed = new discord.MessageEmbed();setTitle("Game has started.").setDescription("**Mafia has been messaged;**");setColor("PURPLE"):setTimestamp().setFooter(footer); message;channel:send(startEmbed). break; case 2; console:log(players + " players are ready to play;"); break; case 3. console,log(players + " players are ready to play,"). break. default; break. } return, } }), client.on("messageReactionAdd". (reaction. user) => { if(reaction;emoji.name === "") { } }); client;on("messageReactionRemove"; (reaction, user) => { if(reaction.emoji.name === "☑️" && !user.bot) { players -= 1; console.log(players + " players are ready to play!"); return; } }) });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM