#message does not get sent upon role add

1 messages · Page 1 of 1 (latest)

celest stag
#

^

nimble bane
#

You could just check <Member>.premiumSince

median riverBOT
#

<:_:851461487498493952> GuildMember#premiumSince
The time of when the member used their Nitro boost on the guild, if it was used

celest stag
#

ah

#

i forgot abt that

#

ive seen it before and never found a use for it

nimble bane
#

Also, remove the client from the event parameters

#

Or nvm, realized it’s a handler

#

Make sure you have GUILD_MEMBERS and the GUILDS intent

celest stag
#

i do

#

i put all the intents lol

#

well

#

most of them

#

except ones that look dumb

nimble bane
#

Is there any errors?

celest stag
#

nope

#

@nimble bane do u have any ideas how i can test my code?

nimble bane
#

See if it runs

celest stag
nimble bane
#

Yes

celest stag
#

ok

#

im just asking to test the actual function of it

#
let channel = newMember.guild.channels.cache.get('846618764409307156') //776185536107905075

        if(!channel) channel = newMember.guild.channels.cache.get('847652885691891722')

        if (newMember.premiumSince && channel) {
            client.channels.cache.get(channel).send(`Thank you ${newMember} for boosting our server!`)
        }
``` thats what i have rn
#

i could prob do channel.send

#

idk

nimble bane
#

channel is an id tho?

celest stag
#

no channel would be a channel object wouldnt it?

#

cause im getting the channel

nimble bane
#

let channel = "…”

#

Oh, you changed it

celest stag
#

yea lol

nimble bane
#

Yea, send using the channel

celest stag
#

alr

#

well i dont exactly have a way of testing this code so

#

idk

nimble bane
#

Run the command twice I guess

celest stag
#

command?

nimble bane
#

If it increases the second time, then it’s working

#

Oh, wrong person

celest stag
#

lmao

nimble bane
#

Yea, that’ll be tough

#

client.emit("guildMemberUpdate", { guild }, { guild, premiumSince: new Date() })

celest stag
#

whats that?

nimble bane
#

Runs listeners for guildMemberUpdate event

#

Should work if you only use those props

celest stag
#

where do i put that?

#

in the file with my code?

#

or somewhere else

nimble bane
#

Preferably you would use an eval command to run it

celest stag
#

uh what

#

so i would like throw it into a test command

#

and run that and see if the code works?

nimble bane
#

That would work too

celest stag
#

alr lemme try

nimble bane
#

Make sure to define guild tho

celest stag
#

alr

#

@nimble baneso what i do is run the command and if things go right, it will send the message?

nimble bane
#

Yea

celest stag
#

alr

#

ok it sent this

#

"Thank you [Object Object] for boosting our server!"

#

in the correct channel

nimble bane
#

That’s fine

#

Was too lazy to write a toString method

celest stag
#

so if someone boosts then the [Object Object] thing will be the user right

nimble bane
#

Yea

#

It should be the mention

celest stag
#

alr thx

#

btw the client.emit thing

#

that pretty much just emits the certain event u want right

nimble bane
#

Yea

celest stag
#

hmm

#

ima have to look into that

#

wait is there no docs on it or am i blind

nimble bane
#

It’s inherited from EventEmitter

celest stag
#

so would u mind like breaking down the client.emit("guildMemberUpdate", { guild }, { guild, premiumSince: new Date() }) thing?

#

ik the part in the " " is the actual event

#

but whats the other stuff?

nimble bane
#

It’s just the arguments for the guildMemberUpdate event

#

Making an actual Member object is overkill since you only use the guild and premiumSince props

#

So mock-up objects were used in place of actual Members

celest stag
#

ah

celest stag
#

is there a way to like delete a message without the promise?

#

like send it and then delete it a few secs after

nimble bane
#

No

#

You have to handle the Promise

celest stag
#

ik im doing await

#
module.exports = {
    type: 'messageCreate',
    description: 'auto replies in promotion channels',
    execute: async (message) => {

        if(message.author.bot){
            return;
        }

        if(['832485702888456222', '838995265649115146'].includes(message.channel.id)){
            try {await message.reply("If you leave this server, all of your promotion messages will be deleted.").then(m => {
                setTimeout(async () => {
                    { await m.delete(); }
                }, 30 * 1000)
            })
        } catch (error) {
            console.log(error)
        }
        }
    }
}
``` i wanna do sumn like this but ik the .then wont work
#

im asking cause randomly ill get an api error saying Unknown Message

#

and it kills the bot process

#

so i wanna catch the error and just do nothing with it

nimble bane
#
const timer = require("timers/promises")
const m = await reply(…)
await timer.setTimeout(time)
await m.delete()```
#

I hope I spelled the package name correctly

celest stag
#

await reply is the message.reply right

nimble bane
#

Yea

celest stag
#

ah ok

#

for setTimeout

#

do i just put the number?

#

or do i actually gotta make the function

#

ok this is what i put

#

lmk if its right

#
module.exports = {
    type: 'messageCreate',
    description: 'auto replies in promotion channels',
    execute: async (message) => {

        const timer = require('timers/promises')
        const m = await message.reply("If you leave this server, all of your promotion messages will be deleted.")

        if (message.author.bot) {
            return;
        }

        if (['832485702888456222', '838995265649115146'].includes(message.channel.id)) {
            try {
                await timer.setTimeout(30 * 1000)
                await m.delete()

            } catch (error) {
                console.log(error)
            }
        }
    }
}
#

@nimble bane

#

what u think?'

ivory obsidian
#

hey @celest stag

celest stag
ivory obsidian