Answer the question
In order to leave comments, you need to log in
Why can't the Discord bot change the message?
I have commands like /question; /suggestion; /bug; All of these commands send messages to the same channels as their name. I think we've cleared that up. The commands themselves work fine, but I also have the /edit command, as you understand, it changes the message.
Let's analyze the /question and /edit commands,
all commands except /edit create an ID for themselves, and for this I write them back to the local file.
Syntax:
/question -q Text
/edit ID -q Text
Now the code itself:
if(message.content.startsWith("/edit")) {
deleteLastM();
var tokens = message.content.split(" ");
const MTid = tokens[1];
if (MTid == null || MTid == undefined) return message.author.send("Будьте добры указать ID сообщения, которого вы пытаетесь изменить.");
else if (db.get(MTid)) {
const Msg = db.get(MTid);
const RID = parseInt(MTid, 10);
async function EditMessage() {
let someserver = client.guilds.cache.get('686225794766209088');
let somechannel = someserver.channels.cache.get(Msg.channelid);
let somemessage = await somechannel.messages.fetch(Msg.realid);
if (Msg.type == "question") {
const Color = Msg.color;
const questions = message.content.split("-q");
var questionembed = new Discord.MessageEmbed()
.setTitle("Вопрос")
.setAuthor(Author, MyAvatar)
.setColor(`${Color}`)
.setFooter(`#${RID}`)
.addFields(
{name: "\u200B", value: `${questions[1]}`}
)
db.set(`${RID}`, {realid: `${Msg.realid}`, type: "question", channelid: `${Msg.channelid}`, color: `${Color}`, text: `${questions[1]}`,
userpostid: `${Msg.userpostid}`, author: `${Msg.author}`, authoravatar: `${Msg.authoravatar}`});
somemessage.edit(questionembed);
message.channel.send("Изменения успешны!").then(msg => {
msg.delete({timeout: 10000})
});
}
EditMessage();
}
}
if (server = '686225794766209088' && message.content.startsWith("/question"))
{
var GetLastMID = GetNewID();
const Color = RColor();
const text = message.content.split("-q");
deleteLastM();
var embed = new Discord.MessageEmbed()
.setTitle("Вопрос")
.setAuthor(Author, MyAvatar)
.setColor(`${Color}`)
.setFooter(`#${GetLastMID}`)
.addFields(
{name: "\u200B", value: `${text[1]}`}
)
message.channel.send(embed).then(msg => {
msg.delete({timeout: 60000})
}
);
client.channels.cache.find(e=>e.name == "questions")
.send(embed).then( question =>
db.set(`${GetLastMID}`, {realid: `${question.id}`, type: "question", channelid:`${message.channel.id}`, color: `${Color}`, text: `${text[1]}`,
userpostid: `${user_id}`, author: `${Author}`, authoravatar: `${MyAvatar}`})
);
let somemessage = await somechannel.messages.fetch(Msg.realid);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question