#mongo stff
1 messages · Page 1 of 1 (latest)
const mongoose = require('mongoose')
const Log = new mongoose.Schema({
guild: String,
channel: String,
user: String,
content: Array
})
module.exports = mongoose.model("Logchannelset", Log);
Yeah
Yep
im using a command
k
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?
Yes
You can remove it
ok
Make a model and call it guild-schema.js
Change the guildData to the right file line 3
i did
Log channel
ok
const channel = message.mentions.channels.first().id
ok
Yep
ok did it
Can you show me you current log file?
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?
Under
guild.save
}
Here
No
in log?
Oh yea, replace it with channelM
channelM?
ok
got it
now do i do channel.send({embeds: [channelem]})
?
Also channel.save
Do you get any more errors if you run it?
im trying it rn
Okey
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>
Mhh