#mongo stff

1 messages · Page 1 of 1 (latest)

uneven basin
#

const mongoose = require('mongoose')

const Log = new mongoose.Schema({
guild: String,
channel: String,
user: String,
content: Array
})

module.exports = mongoose.model("Logchannelset", Log);

feral flint
#

Yeah

uneven basin
#

wait what mesage file

#

messageCreate

#

?

feral flint
uneven basin
#

im using a command

feral flint
#

Yea I know

#

But if you do it like this you don’t need to copy it

#

To every file

uneven basin
#

k

feral flint
#

Or you can do it in the command it self

#

But that’s up to you

uneven basin
#
const client = require("../index");
const {MessageEmbed, Discord} = require("discord.js")
const guildData = require('../model/logchanneldb')

client.on("messageCreate", async (message) => {
    try{
        guildData = await guildModel.findOne({ Guild: message.guild.id });
        if(!guildData) { 
          let guild = await guildModel.create({
              Guild: message.guild.id,
              GuildName: message.guild.name,
              LogChannel: channeld
        });
        guild.save();
        }
        
        } catch (err) {
        return console.log(err);
        }
    if (
        message.author.bot ||
        !message.guild ||
        !message.content.toLowerCase().startsWith(client.config.prefix)
    )
        return;

    const [cmd, ...args] = message.content
        .slice(client.config.prefix.length)
        .trim()
        .split(/ +/g);

        
       
    const command = client.commands.get(cmd.toLowerCase()) || client.commands.find(c => c.aliases?.includes(cmd.toLowerCase()));
    if (!command) return 
    if (command) {
        
        if (!message.member.permissions.has(command.UserPerms || [])) return message.channel.send(`You need \`${command.UserPerms || []}\` Permissions`) 

       
        if (!message.guild.me.permissions.has(command.BotPerms || [])) return message.channel.send(`I need \`${command.BotPerms || []}\` Permissions`)

        await command.run(client, message, args, Discord)
    } 
})```
#

like this?

feral flint
#

Yes

uneven basin
#

ok

#

wait whats channeld

feral flint
#

You can remove it

uneven basin
feral flint
#

Make a model and call it guild-schema.js

uneven basin
#

i did

feral flint
uneven basin
feral flint
#

Nice

#

Now in the command file

#

Require the model

uneven basin
#

ok

#

yes i did

#

which one

#

log channel set?

#

or ban?

feral flint
#

Log channel

uneven basin
#

then where will the channel be passed it

#

in

feral flint
#

After that

#

First the code need to know what’s guild data

uneven basin
#

ok

feral flint
#

const channel = message.mentions.channels.first().id

uneven basin
#

ok

feral flint
#

Wait, add a LogChannel: ‘Disabled’

#

To both files

uneven basin
#

where

#

in message create?

#

and log

#

?

feral flint
#

Yep

uneven basin
#

ok did it

feral flint
#

Can you show me you current log file?

uneven basin
#

const {Message, MessageEmbed, MessageActionRow, MessageButton, Client} = require('discord.js');
const guildData = require('../../model/guildlogs')
module.exports = {
name: 'logchannelset',
/**
*
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async(client, message, args) => {
const channel = message.mentions.channels.first().id
if(!channel) return message.reply('Please specify a channel')

    guildData = await guildModel.findOne({ Guild: message.guild.id });
if(!guildData) { 
 let guild = await guildModel.create({
  Guild: message.guild.id,
  GuildName: message.guild.name,
  LogChannel: Disabled
});
guild.save();
}

const channelem = new MessageEmbed()
.setColor('GREEN')
.setTitle('Log channel set')
.setDescription('A log channel is where ban logs and such will be sent.')

message.reply('Log channel updated!')
}

}

#

where?

feral flint
#

Under

guild.save
}
Here

uneven basin
#

k

#

in both files?

feral flint
#

No

uneven basin
#

in log?

feral flint
#

Only log yes

#

Now try it please

#

And send me any errors

uneven basin
#

ok

feral flint
#

Oh yea, replace it with channelM

uneven basin
#

ok

#

got it

#

now do i do channel.send({embeds: [channelem]})

#

?

feral flint
#

Also channel.save

uneven basin
feral flint
#

Do you get any more errors if you run it?

uneven basin
feral flint
#

Okey

uneven basin
#

const {Message, MessageEmbed, MessageActionRow, MessageButton, Client} = require('discord.js');
const guildData = require('../../model/guildlogs')
module.exports = {
name: 'logchannelset',
/**
*
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async(client, message, args) => {
const channel = message.mentions.channels.first().id
if(!channel) return message.reply('Please specify a channel')

    guildData = await guildData.findOne({ Guild: message.guild.id });
if(!guildData) { 
 let guild = await guildData.create({
  Guild: message.guild.id,
  GuildName: message.guild.name,
  LogChannel: Disabled
});
guild.save();
}
const channelM = await guildData.findOneAndUpdate(
    {
    Guild: message.guild.id,
    LogChannel: channel
}

)
channel.save();

const channelem = new MessageEmbed()
.setColor('GREEN')
.setTitle('Log channel set')
.setDescription('A log channel is where ban logs and such will be sent.')

message.reply('Log channel updated!')
channel.send({embeds: [channelem]})
}

}

#

C:\Users\astro\Documents\GitHub\Shield\commands\moderation\logchannel.js:15
guildData = await guildData.findOne({ Guild: message.guild.id });
^

TypeError: Assignment to constant variable.
at Object.run (C:\Users\astro\Documents\GitHub\Shield\commands\moderation\logchannel.js:15:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.<anonymous> (C:\Users\astro\Documents\GitHub\Shield\events\messageCreate.js:30:9)

Node.js v17.6.0
PS C:\Users\astro\Documents\GitHub\Shield>

feral flint
#

Mhh