Code :
let prefix = client.guildSettings.get(message.guild.id,"prefix")
Error :
TypeError: Cannot read property ‘get’ of undefined
Can someone help?
Code :
let prefix = client.guildSettings.get(message.guild.id,"prefix")
Error :
TypeError: Cannot read property ‘get’ of undefined
Can someone help?
I am using enmap…
Please help
please
print("please read and solve")
Please be patient and calm down. Nobody wants to help you when you are being rude.
Sorry
Can you help though?
I don’t have the answer (as I don’t really make Discord Bots) , I’ll ask somebody else for you though.
So what should I do instead?
I’m not sure. Can I ask what the function is supposed to do? Why do you need it?
I need it to define the custom prefix. I’m using Enmap for it.
Hi! Have you defined client.guildSettings
yourself? Is it anywhere else in your code. If so, can you send the code?
Nope, i didn’t define it.
my code is here :
const Discord = require('discord.js')
const fs = require('fs');
const client = new Discord.Client()
const { token } = require('./config.json');
const enmap = require('enmap')
const defaultsettings = require("./util/defaultsettings")
const config = require("./config.json")
// create a new Discord client
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('USERS TYPE -help', { type: 'WATCHING' });
});
client.on("guildCreate",(guild)=>{
createserver(guild.id, defaultsettings)
})
client.on("guildDelete",(guild)=>{
client.guildSettings.delete(guild.id)
})
client.on('message', message => {
let prefix = client.guildSettings.get(message.guild.id,prefix)
if (!message.content.startsWith(prefix) || message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/)
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
try {
if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!');
}
command.execute(message, args);
} catch (error) {
console.log(error);
message.reply('there was an error trying to execute that command!');
}
});
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
// login to Discord with your app's token
client.login(token);
Aha! I get you now!
Looks like you need to use this instead:
let prefix = client.settings.get(message.guild.id,"prefix")
Hope this helps and Happy Glitching
Eddie
It still says a error. The same eror
Can I see the /util/defaultsettings
file?
I don’t know…
const defaultsettings = {
prefix: "!",
deletemessage: true,
owners: []
}
module.exports = defaultsettings
there gave you the code
Hi @DaRealMiniToon
Have you got code like this somewhere?
client.settings = new enmap({
name: "settings",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep'
});
Nope, but where should I add it?
I
I would put it after you define enmap
(This line: const enmap = require('enmap')
)
Thanks! That fixed old one. New error!
let prefix = client.settings.get(message.guild.id,prefix)
ReferenceError: Cannot access ‘prefix’ before initialization
@EddiesTech
Could you also help with this one? <3
In enmap the path needs to be a string. Your passing a variable you haven’t defined yet.
Try:
let prefix = client.settings.get(message.guild.id, 'prefix')
Thanks lol! Fixed.
if (!this.has(key)) throw new Err(`The key "${key}" does not exist in the enmap "${this.name}"`, 'EnmapPathError');
^
CustomError [EnmapPathError]: The key "755528648152580167" does not exist in the enmap "settings"
Add this:
const guildConf = client.settings.ensure(message.guild.id, defaultsettings);
Ofc, but now it just don’t run any code.
now what
const Discord = require('discord.js')
const fs = require('fs');
const client = new Discord.Client()
const { token } = require('./config.json');
const enmap = require('enmap')
const defaultsettings = require("./util/defaultsettings")
const defaultPrefix = "-"
const config = require("./config.json")
client.settings = new enmap({
name: "settings",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep'
});
// create a new Discord client
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('USERS TYPE -help', { type: 'WATCHING' });
});
function createserver(guildid, object){
client.settings.ensure(guildid, object)
}
client.on("guildCreate",(guild)=>{
createserver(guild.id, defaultsettings)
})
client.on("guildDelete",(guild)=>{
client.settings.delete(guild.id)
})
client.on('message', message => {
const guildConf = client.settings.ensure(message.guild.id, defaultsettings);
let prefix = client.settings.get(message.guild.id,'prefix')
if (!prefix){
prefix = defaultPrefix
message.reply("no prefix configured")
}
if (!message.content.startsWith(prefix) || message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/)
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
console.log(commandName)
try {
if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!');
}
command.execute(message, args);
} catch (error) {
console.log(error);
message.reply('there was an error trying to execute that command!');
}
});
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
// login to Discord with your app's token
client.login(token);
const guildConf = client.settings.ensure(message.guild.id, defaultsettings);
^
TypeError: Cannot read property ‘id’ of null
so its wrong
const guildConf = client.settings.ensure(message.guild.id, defaultsettings);
^
TypeError: Cannot read property ‘id’ of null
I’m using discord.js v12. Not discord.js v11