TypeError: Cannot read property 'get' of undefined

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 :frowning:



print("please read and solve")

Please be patient and calm down. Nobody wants to help you when you are being rude.


Sorry :frowning:

Can you help though? :slight_smile:

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?

1 Like

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', () => {
	client.user.setActivity('USERS TYPE -help', { type: 'WATCHING' });
    createserver(guild.id, defaultsettings)


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) {
	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

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 :slight_smile: :glitch:


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'