Javascript discord.js-将代码放入嵌入
我有以下代码:Javascript discord.js-将代码放入嵌入,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我有以下代码: ("...............I don't know what exactly you are trying to do. I guess what you made is an animation, if not, and you just want to print litterally this piece of code in your embed, just put this piece of code inside backticks descri
("...............I don't know what exactly you are trying to do. I guess what you made is an animation, if not, and you just want to print litterally this piece of code in your embed, just put this piece of code inside backticks
description: `("...............Instead of deleting it and sending it again you can create a variable of the lastMessage (you might have to make a delay before selecting it) then do message.edit()If I'm understanding you correctly, you want to send the first snippet of code into the description field and edit it, trying to make it be an animation?
I haven't tried editing an embedded message before but this is how I would go around it.
const sendCarAnimation = async (message) => {
// define the steps here
const animationSteps = [
"...............Got it! What I did to solve it was on startup, to grab the right channel using channel = client.user.guilds.cache.get("Guild id here").channels.cache.get("channel id")
, built an embed that just said old, and then sent the embed.
I did include an array of animation steps like Emil Choparinov, and a msgProgress
variable. The bot detects when a message is sent, and checks if (msg.content === '')
. if true, it will set the recievedEmbed
constant to msg.embeds[0]
.
Then, a new const, embed
, is set to a new Discord.MessageEmbed
, using the old embed as a starting point, and setting the title to animationSteps[msgProgress]
. It then calls msg.edit(embed)
, and changes the msgProgress
variable by 1.
There is also a client.on('messageUpdate', msg => {})
, and it has the same code, except at the start, it checks if msg progress > 9, and if so, it returns. Here is the code:
require('dotenv').config();
const Discord = require('discord.js');
const client = new Discord.Client();
var channel;
const genericEmbed = new Discord.MessageEmbed()
.setTitle("old");
const animationSteps = [
"...............:red_car:......",
"............:red_car:.........",
"........:red_car:............",
".....:red_car:...............",
"..:red_car:..................",
":red_car:....................",
":open_mouth:....:red_car:..............",
".:cold_sweat:..:red_car:......................",
"..:tired_face:.:red_car:......................",
"...:ghost::red_car:......................"
];
var msgProgress = 0;
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
channel = client.guilds.cache.get("753227876207165570").channels.cache.get("753227876207165573");
console.log(channel);
const firstEmbed = new Discord.MessageEmbed()
.setTitle("old");
channel.send(firstEmbed);
});
client.on('message', msg => {
if (msg.content === '') {
console.log("good");
channel = msg.channel;
const receivedEmbed = msg.embeds[0];
const embed = new Discord.MessageEmbed(receivedEmbed)
.setTitle(animationSteps[msgProgress]);
msg.edit(embed);
msgProgress++;
}
});
client.on('messageUpdate', msg => {
if (msgProgress > 9) {
return;
}
if (msg.content === '') {
console.log("good");
channel = msg.channel;
const receivedEmbed = msg.embeds[0];
const embed = new Discord.MessageEmbed(receivedEmbed)
.setTitle(animationSteps[msgProgress]);
msg.edit(embed);
msgProgress++;
}
});
client.login(process.env.DISCORD_TOKEN);
(“……………我不知道你到底想做什么。我猜你制作的是一个动画,如果不是,你只是想在你的嵌入中随意打印这段代码,只需将这段代码放在背景标记中
description:`(……我不知道你到底想做什么。我猜你制作的是一个动画,如果不是,你只是想在你的嵌入中随意打印这段代码,只需将这段代码放在背景中即可
说明:`(……您可以创建lastMessage的变量(选择前可能需要延迟),然后执行message.edit()您可以创建lastMessage的变量,而不是删除它并再次发送(您可能需要在选择之前进行延迟)然后执行message.edit()如果我理解正确,您是否希望将第一段代码发送到“描述”字段并对其进行编辑,尝试使其成为动画
我以前没有尝试过编辑嵌入的消息,但我会这样做
const sendCarAnimation=async(消息)=>{
//在这里定义步骤
常量动画步骤=[
“………如果我理解正确,您是否希望将第一段代码发送到“描述”字段并对其进行编辑,以使其成为动画
我以前没有尝试过编辑嵌入的消息,但我会这样做
const sendCarAnimation=async(消息)=>{
//在这里定义步骤
常量动画步骤=[
“……………明白了!我所做的是在启动时,使用channel=client.user.guilds.cache.get(“此处的帮会id”).channels.cache.get(“channel id”)
,获取正确的频道,构建一个只说旧的嵌入,然后发送嵌入
我确实包括了一系列的动画步骤,比如Emil Choparinov和一个msgProgress
变量。机器人会检测消息何时发送,并检查是否(msg.content=='')
。如果为真,它会将receivedembed
常量设置为msg.embeddes[0]
然后,一个新的常量embed
被设置为一个新的Discord.MessageEmbed
,使用旧的嵌入作为起点,并将标题设置为animationSteps[msgProgress]
。然后调用msg.edit(embed)
,并将msgProgress
变量更改为1
还有一个客户端。在('messageUpdate',msg=>{})
上,它有相同的代码,除了在开始时,它检查msg progress>9,如果是,它返回。下面是代码:
希望这有帮助!明白了!我所做的是在启动时,使用channel=client.user.guilds.cache.get(“此处的帮会id”).channels.cache.get(“channel id”)
获取正确的频道,构建了一个只说旧的嵌入,然后发送了嵌入
我确实包括了一系列的动画步骤,比如Emil Choparinov和一个msgProgress
变量。机器人会检测消息何时发送,并检查是否(msg.content=='')
。如果为真,它会将receivedembed
常量设置为msg.embeddes[0]
然后,一个新的常量embed
被设置为一个新的Discord.MessageEmbed
,使用旧的嵌入作为起点,并将标题设置为animationSteps[msgProgress]
。然后调用msg.edit(embed)
,并将msgProgress
变量更改为1
还有一个客户端。在('messageUpdate',msg=>{})
上,它有相同的代码,除了在开始时,它检查msg progress>9,如果是,它返回。下面是代码:
希望这有帮助!