discord.js Cannot read property ‘guild’ of undefined

Solution for discord.js Cannot read property ‘guild’ of undefined
is Given Below:

I’ve already looked through a few tutorials and pages, but couldn’t find a working version to check whether the author has the appropriate role.

My last tryed code:

const fs = require('fs');
const Discord = require('discord.js');
const {
} = require('./config.json');

const client = new Discord.Client();

function loadServer() {
  server = getJ('./server.json');

function abnahme(message){
let charRole = message.guild.roles.find("name", "Character-Abnehmer");

if (message.content == 'accepted' && message.member.roles.has(charRole)) {
}else {


client.once('ready', () => {

client.on('message', message => {      
if (message.content.startsWith(server.prefix)) {

const args = message.content.slice(server.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
    message.channel.send(``command: ${command} args: ${args}``);

      if(command == 'abnahme'){



Can someone give me an example of how I can just query the role?

The easiest way to see if a member has a role is with GuildMember.roles.cache.has().

Use this code

client.on('message', async msg => {
let memberHasRole = msg.member.roles.cache.has('role-id');
//true if member has the role, false if they don’t