#Log messages after deleting. module isn't working

1 messages · Page 1 of 1 (latest)

frozen swift
#

Ok, after trying the initial help provided on the support channel, it's still not wrking, idk if i made a mistake

fossil dagger
#

Can you update your code

#

Because thats still the wrong embed sending

wraith vapor
#

console log channel and make sure that's a thing

#

unless the event just doesn't fire

frozen swift
# fossil dagger Because thats still the wrong embed sending

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] });
  });
wraith vapor
#

does the event fire?

frozen swift
wraith vapor
#

what intents do u use?

frozen swift
#

it's not sending the console.log

wraith vapor
#

yeah where do u define ur client

frozen swift
#

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

wraith vapor
#

hmm

#

add

#

GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent and try

frozen swift
#

yea... tbh im still new on bot development, this proyect was the 2nd attempt, the first one was on discord.php lol

wraith vapor
#

yikes

#

php xd

frozen swift
#

yea... idk if i was drunk or what

wraith vapor
#

did u try that?

frozen swift
#

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!

fossil dagger
#

You dont need MessageContent for a messageDelete event

frozen swift
#

now it broke other module lol

fossil dagger
#

it doesnt include content

#

You would need it to cache content of messages when you recieve them in messageCreate events though

wraith vapor
#

message delete doesn't include content?

fossil dagger
#

Correct

wraith vapor
#

for all apps?

frozen swift
fossil dagger
#

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

wraith vapor
#

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

fossil dagger
#

possibly

wraith vapor
#

yeah cause I just did message.content in the messagDelete event

#

okay remove the content bit and try again?

frozen swift
#

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

wraith vapor
#

Didn't know that how it worked tbh

frozen swift
#

idk either. it's just an assumption

wraith vapor
#

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

frozen swift
#

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...

wraith vapor
#

okay so the event fires but what's the error again?

frozen swift
#

the event doesn't even fires

wraith vapor
#

oh yikes

frozen swift
#

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?

fossil dagger
#

nope, no permissions required

frozen swift
#

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?

fossil dagger
#

Can you show your client constructor again please

frozen swift
frozen swift
fossil dagger
#

You're... Still missing the GuildMessages intent

#

I thought someone told you to add that

frozen swift
#

wait what?

frozen swift
# fossil dagger You're... Still missing the GuildMessages intent

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)


fossil dagger
#

So what's line 82

frozen swift
#

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

frozen swift
#

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 :')

wraith vapor
#

no worries