Skip to content
Advertisement

Discord.js v12 send the error message from dm

I want to sending the error message from dm to users. But I’m getting ReferenceError: error is not defined error. How can I fix this?

if (error) {
   client.users.cache.get(message.author.id).send(error)
}

Here is my index.js

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`x1b[33m${client.user.tag} x1b[0mgiriş yaptı!`);
  client.user.setActivity(`Online on ${client.guilds.cache.size} servers`, {type: 'WATCHING'})
});

client.on('message', message => {
  const { channel } = message

  if (channel.type === 'news') {
    message.crosspost().catch(console.error)
    console.log(`x1b[31m${message.guild.name}x1b[0m sunucusunda duyuru yapıldı! x1b[33m(ID: ${message.guild.id})`)
  }

  if (error) {
    client.users.cache.get(message.author.id).send(error)
  }
});

Advertisement

Answer

Problem is solved.

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`x1b[33m${client.user.tag} x1b[0mgiriş yaptı!`);
  client.user.setActivity(`Online on ${client.guilds.cache.size} servers`, {type: 'WATCHING'})
});

client.on('message', message => {
  const { channel } = message

  if (channel.type === 'news') {
    message.crosspost().catch(error => {
      console.log(error)
      message.author.send(error.message)
    })
    console.log(`x1b[31m${message.guild.name}x1b[0m sunucusunda duyuru yapıldı! x1b[33m(ID: ${message.guild.id})`)
  }
});
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement