Answer the question
In order to leave comments, you need to log in
Why is the Discord bot message not changing?
Good day, I've been struggling with the code for 2 days, and I decided to turn here for help.
Let's talk a little about the bot, it already has 100% working /bug and /edit commands, the first one creates a message and sends it to a channel where others are denied access, but if someone made mistakes, do you need to fix it somehow? There is a /edit command for this, you understand the essence. I want to say that for the /edit command to work, I save the data to a local file.
I started working on the /repeatto command, its essence is to send a copy of the message to another channel. This is where the interesting moment begins, here is the code for the /repeatto command for a rough understanding of what I'm doing:
if(message.content.startsWith("/repeatto")) {
deleteLastM();
if (!message.mentions.channels.first()) return message.author.send("Укажите один канал");
if (message.mentions.channels.size == 1){
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.author.send("У вас недостаточно прав"), deleteLastM();
const textrepeat = TRepeat();
const repeatname = TRepeatName();
var ID = GetNewID();
const Mchannel = message.mentions.channels.first().id;
var embed = new Discord.MessageEmbed()
.setColor('#000000')
.setFooter(`#${ID}`)
.setTitle(`${repeatname}`)
.addField("\u200B", `${textrepeat}`)
client.channels.cache.get(Mchannel)
.send(embed).then( repeat =>
db.set(`${ID}`, {realid: `${repeat.id}`, type: "repeated", channelid:`${Mchannel}`, rname:`${repeatname}`, rtext: `${textrepeat}`})
);
}
}
if(server = '686225794766209088' && 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.has(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 == "repeated"){
const ETrepeatname = Msg.rname
const ETrepeat = Msg.rtext
Erepeatname = function() {
if (message.content.includes("-n")) return TRepeatName()
else return ETrepeatname
}
Erepeattext = function() {
if (message.content.includes("-r")) return TRepeat()
else return ETrepeat
}
const dbErepeatname = Erepeatname();
const dbErepeat = Erepeattext();
var repeatedembed = new Discord.MessageEmbed()
.setColor('#000000')
.setFooter(`#${RID}`)
.setTitle(`${dbErepeatname}`)
.addField("\u200B", `${dbErepeat}`)
db.set(`${RID}`, {realid: `${Msg.realid}`, type: "repeated", channelid:`${Msg.chennelid}`, rname: `${dbErepeatname}`, rtext: `${dbErepeat}`});
somemessage.edit(repeatedembed);
message.channel.send("Изменения успешны!").then(msg => {
msg.delete({timeout: 10000})
});
}
}
EditMessage();
}
}
let someserver = client.guilds.cache.get('686225794766209088');
let somechannel = someserver.channels.cache.get(Msg.channelid);
let somemessage = await somechannel.messages.fetch(Msg.realid);
// < TypeError: Cannot read property 'messages' of undefined
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