#The code doesn't have a bug, but it doesn't work.

9 messages · Page 1 of 1 (latest)

potent oceanBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
quick charm
#
        if (message.attachments.size > 0) {
            message.react(':x:');
            return member.send("I cannot send this massage!")
        }

        const postChannel = guild.channels.cache.find(c => c.name === `${message.author.id}`);

        if (postChannel) {
            
            const embed = new EmbedBuilder()
            .setColor("Orange")
            .setAuthor({ name: `${message.author.username}`, iconURL: `${message.author.displayAvatarURL()}`})
            .setDescription(`${message.content}`)

            postChannel.send({ embeds: [embed] });
            message.react(`📧`)
            return;


        }

        const category = guild.channels.cache.get('1202044175198204016');
        const channel = await guild.channels.create({
            name: message.author.id,
            type: ChannelType.GuildText,
            parent: category,
            topic: `A mail sent by ${message.author.tag}`
        })
        
        member.send(`Your modmail conversation has been started in ${guild.name}`).catch(err => {
            return;
        })

        const embed = new EmbedBuilder()
        .setTitle(`NEW MODMAIL`)
        .setColor("Orange")
        .setAuthor({ name: `${message.author.username}` , iconURL: `${message.author.displayAvatarURL()}`})
        .setDescription(`${message.content}`)
        .setTimestamp()
        .setFooter({ text: "Use the button below to close this mail" })

        const button = new ActionRowBuilder()
        .addComponents(
            new ButtonBuilder()
            .setCustomId('button')
            .setStyle(ButtonStyle.Danger)
            .setLabel('Close')
            .setEmoji(':closed_lock_with_key:')
        )
#
        const m = await channel.send({ embeds: [embed], components: [buttons] });

        const collector = m.createMessageComponentCollector();

        collector.on('collect', async i => {
            if (i.customId == 'buttons') {
                await channel.delete();
                member.send(`Your modmail conversation in ${guild.name} has been closed by a moderator`)
            }
        })

        m.pin();
        message.react('📧');

    }
})

client.on(Events.MessageCreate, async message => {
    if (message.channel.type === ChannelType.GuildText) {

        const guildID = '1160869445988794418'
        const guild = client.guilds.cache.get(guildID);

        modSchema.findOne({ Guild: guild.id, User: message.channel.name }, async (err, data) => {

            if (data == null) return;

            const colChannel = guild.channels.cache.find(c => c.name === `${data.User}`);

            if (message.channel === colChannel) {

                if (message.author.bot) return;

                const memberID = data.User;
                const member = await client.users.fetch(memberID);

                if (message.attachments.size > 0) {
                    message.react('❌');
                    return member.send("I cannot send this massage!")
                }

                message.react('📧')

                const embed = new EmbedBuilder()
                .setColor("Orange")
                .setAuthor({ name: `${message.author.username}`, iconURL: `${message.author.displayAvatarURL()}` })
                .setDescription(`${message.content}`)

                member.send({ embeds: [embed] })
            }
        })
    }
})
opaque fable
#

in what way does it not work?
how do you expect it to behave, and in what way does its current behavior not meet this?
have you logged throughout to see what executes and what doesn't?
does this event emit at all?
do you have the proper intents?
( #how-to-get-help )

#

as a side note, it appears that you have multiple MessageCreate listeners
in general, it's recommended to just have one listener per event and delegate work from there rather than multiple listeners

quick charm
#

When the message is sent to the bot, the channel is not created and the message is not forwarded to the person

opaque fable
#

have you logged throughout to see what executes and what doesn't?
does this event emit at all?
do you have the proper intents?
( #how-to-get-help )

quick charm