#Log messages after deleting. module isn't working
1 messages · Page 1 of 1 (latest)
Ok, after trying the initial help provided on the support channel, it's still not wrking, idk if i made a mistake
console log channel and make sure that's a thing
unless the event just doesn't fire
yup.
const channel = client.channels.cache.get(DELCHAN_ID);
console.log('message deleted...')
const logEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Message Deleted')
.setDescription(`A message by ${message.author} was deleted in ${message.channel}.`)
.addField('Content', message.content)
.setTimestamp();
channel.send({ embeds: [logEmbed] });
});
does the event fire?
nope
what intents do u use?
it's not sending the console.log
yeah where do u define ur client
on index.js
const client = new Client({ partials: [Partials.Message, Partials.Channel, Partials.Reaction], intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
client.once(Events.ClientReady, () => {
const channelId = config.channel_id;
const channel = client.channels.cache.get(channelId);
try {
channel.send('Hello there, I am online!');
console.log('welcome message sent!')
} catch (error) {
console.log('unable to send online message, but bot is alive. pls check index.js client ready block. error: ',error)
}
console.log('Ready!');
});
wait
hmm
add
GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent and try
yea... tbh im still new on bot development, this proyect was the 2nd attempt, the first one was on discord.php lol
yea... idk if i was drunk or what
did u try that?
unable to send online message, but bot is alive. pls check index.js client ready block. error: TypeError: Cannot read properties of undefined (reading 'send')
at Client.<anonymous> (E:\furryvaley-projects\ProtoDEV\index.js:36:11)
at Object.onceWrapper (node:events:642:26)
at Client.emit (node:events:527:28)
at WebSocketManager.triggerClientReady (E:\folder-projects\ProtoDEV\node_modules\discord.js\src\client\websocket\WebSocketManager.js:385:17)
at WebSocketManager.checkShardsReady (E:\furryvaley-projects\ProtoDEV\node_modules\discord.js\src\client\websocket\WebSocketManager.js:368:10)
at WebSocketShard.<anonymous> (E:\folder\ProtoDEV\node_modules\discord.js\src\client\websocket\WebSocketManager.js:194:14)
at WebSocketShard.emit (node:events:527:28)
at Timeout._onTimeout (E:\folder\ProtoDEV\node_modules\discord.js\src\client\websocket\WebSocketShard.js:544:14)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
Ready!
You dont need MessageContent for a messageDelete event
now it broke other module lol
it doesnt include content
You would need it to cache content of messages when you recieve them in messageCreate events though
message delete doesn't include content?
Correct
for all apps?
exactly. those are not accessible after deletion
I dont know what you mean by this
discord.js only gives you content in the event if it was cached. If the message wasn't cached, there's no way to get its content
I thought message delete included the content that was deleted or am I stupid
oh right, so the message was always cached I'm assuming
possibly
yeah cause I just did message.content in the messagDelete event
okay remove the content bit and try again?
i think that dyno somehow keep the log of all the messages temporaly for each shard, and if a message with id X get deleted (only info fetchable after deletion) and it have a message with id x cached get deleted, it fetchs the content, and place it onto the embed
Didn't know that how it worked tbh
idk either. it's just an assumption
I thought discord provided the content before it was deleted and then the deleted it
but knowing that they don't, they surely cache messages too
ok, this got fixed after removing the MessageContent intent
gonna place it on a try/catch to see if that helps debugging
still doesnt...
try {
const channel = client.channels.cache.get(DELCHAN_ID);
console.log('message deleted...')
const logEmbed = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Message Deleted')
.setDescription(`A message by ${message.author} was deleted in ${message.channel}.`)
.addField('Content', message.content)
.setTimestamp();
channel.send({ embeds: [logEmbed] });
} catch (error) {
console.log('error on message delete module');
}
});
it's not accessing to that module...
okay so the event fires but what's the error again?
the event doesn't even fires
oh yikes
hmmmmmm... i'll read again the docs and see if i can find something
... if this fixes it, idk what im gonna do
still doesnt
maybe i miss some permissions?
nope, no permissions required
tried to replace the module for this...._
that is the suggested code in the docs
but still evetn is not firing
should i ask too on the discord development server?
Can you show your client constructor again please
should i send it on text instead of a screenshot?
You're... Still missing the GuildMessages intent
I thought someone told you to add that
wait what?
ok, just added it. and it dropped error lmao
node:events:505
throw er; // Unhandled 'error' event
^
TypeError: Cannot read properties of null (reading 'id')
at Client.<anonymous> (E:\folder\ProtoDEV\index.js:82:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:384:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
So what's line 82
wait... i know why
it's trying to fetch a var that is not available yet
k now i'll need to implement the embed. I'll be back if i have any issue with that
ok... now i got this
ReferenceError: Discord is not defined
this is the line it gets reffered to:
const logEmbed = new Discord.MessageEmbed().setColor('#ff0000').setTitle('Message Deleted').setDescription(`A message by ${message.author.tag} was deleted in ${message.channel}.`).addField('Content', message.content).setTimestamp();
i think i got it... lemme see
@fossil dagger @wraith vapor THANK YOU!
Now i can move it to production :')
no worries