Discord JS |使用命令编辑嵌入 [英] Discord JS | Edit Embed with command
问题描述
我尝试更改每个命令已发送的嵌入.我得到一个进行嵌入的命令,并将其发送到用户定义的Channel(selchannel)中.但是当我尝试编辑Embed时,我得到了:
I try to change an already send Embed per command. I got an command that makes an embed and sends it in an user defined Channel (selchannel). But when i try to edit the Embed I get:
DiscordAPIError:无法编辑其他用户创作的消息
DiscordAPIError: Cannot edit a message authored by another user
但是消息是由机器人发送的,为什么它这么说呢?
But the Message was send by the bot so why does it say this?
我如何发送原始嵌入内容:
How i send the original Embed:
// constructing Embed...
let messageEmbed = await client.channels.cache.get(selchannel).send({embed: EmbedMessage})
module.exports = {
messageEmbed,
EmbedMessage
}
我如何尝试对其进行
module.exports = {
name: 'edit-embed',
description: 'Edits send Embed',
async execute(message, args) {
const Discord = require('discord.js');
const { messageEmbed } = require('./embed');
const { EmbedMessage } = require('./embed');
const { prefix } = require('/home/ubuntu/discord-bot/main.js');
const sender = `${message.author.tag}`;
const InputSlice = message.content.slice(prefix.length).trim().split(' ');
const sEmbed = args.shift().toLowerCase();
const newEmbed = new Discord.MessageEmbed()
.setColor('#8022FF')
.setTitle('.........:')
.addFields(
{name: '\u200B', value: '\u200B'},
{name: '........: ', value: ' ............' },
{name: '\u200B', value: '\u200B'}
)
.setImage('...........')
.setFooter(`............ -(${sender})-`);
message.edit(sEmbed).then(newEmbed);
}
}
我在做什么错了?
推荐答案
您应该将embed分配给变量作为消息对象,然后可以使用< yourvariable(由bot发送的embed)>.编辑(您的其他变量)
You should probably assign the embed to a variable as a message object, and then you can use <yourvariable (the embed sent by the bot)>.edit(your other variable)
换句话说,您需要向execute()函数添加另一个变量(该消息将作为消息对象)
In other words, you need to add another variable to the execute() function (which would be the message as a message object)
如果您愿意,这里有一个示例(我认为)
if you want, here would be an example of how you could do it (I think)
// constructing Embed...
let messageEmbed = await client.channels.cache.get(selchannel).send({embed: EmbedMessage})
module.exports = {
messageEmbed,
EmbedMessage
}
module.exports = {
name: 'edit-embed',
description: 'Edits send Embed',
async execute(message, args, botEmbed) { //add botEmbed (which is a message object)
const Discord = require('discord.js');
const { messageEmbed } = require('./embed');
const { EmbedMessage } = require('./embed');
const { prefix } = require('/home/ubuntu/discord-bot/main.js');
const sender = `${message.author.tag}`;
const InputSlice = message.content.slice(prefix.length).trim().split(' ');
const sEmbed = args.shift().toLowerCase();
const newEmbed = new Discord.MessageEmbed()
.setColor('#8022FF')
.setTitle('.........:')
.addFields(
{name: '\u200B', value: '\u200B'},
{name: '........: ', value: ' ............' },
{name: '\u200B', value: '\u200B'}
)
.setImage('...........')
.setFooter(`............ -(${sender})-`);
botEmbed.edit(sEmbed).then(newEmbed); //change message to botEmbed
}
,然后在调用edit函数时,只需传入另一个属性,即您发送的嵌入消息的消息对象
and then when you call the edit function, just pass in another property, which would be the message object of the embed that you sent
我希望这行得通!(尚未测试)
I hope this works! (haven't tested it)
这篇关于Discord JS |使用命令编辑嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!