Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Je lance mon bot !

const Discord = require('discord.js');
const client = new Discord.Client();
var prefix = "/";

client.on("ready", () => {
    client.user.setActivity("Le Bot de AlexTheKing !");
    console.log('Prets !');
  }); 

  if (message.content === '/pay') {
    message.reply('Fait un dons sur paypal ! https://www.paypal.me/gael47 :wink: ')
  };

  if (message.content === '/site') {
    message.reply('https://animacraft.fr')
  };

  if (message.content === '/youtube') {
    message.reply('La chaîne youtube de AlexTheKing : https://www.youtube.com/channel/UCKoNqCns-6rmZRQV2MLrrZw ')
  };

  if (message.content === '/avatar') {
    // Send the user's avatar URL
    message.reply(message.author.avatarURL);
  }

  if(message.content === prefix + "info"){
    var info_embed = new Discord.RichEmbed()
    .setColor("#DC143C")
    .setTitle("Les informations de mon Bot et du Serveur !")
    .addField(" :robot: Nom :", `${client.user.tag}`, true)
    .addField("Tag du bot :hash:", `#${client.user.discriminator}`)
    .addField(":id: ", `${client.user.id}`)
    .addField("Tu veux soutenir AlexTheKing ?", " https://www.paypal.me/gael47 :wink: ")
    .addField("Pour voir les commandes du bot :", " /commandes ")
    .addField("Nombre de Membres", message.guild.memberCount)
    .addField("En développement par AlexTheKing", "AlexTheKing")
    .setFooter("Info - Bot")
    message.channel.send(info_embed);
    console.log("Info");
};

if(message.content === prefix + "commandes"){
    var info_embed = new Discord.RichEmbed()
    .setColor("#DC143C")
    .setTitle("Les commandes du bot!")
    .addField("/youtube", " Récuperer le lien de la chaîne YouTube")
    .addField("/avatar", "Voir votre avatar")
    .addField("/pay", "Faire un dons !")
    .setFooter("Commandes - Bot")
    message.channel.send(info_embed);
    console.log("Commandes");
  };

  client.on('guildMemberAdd', member => {
    const welcomechannel = member.guild.channels.find(c => c.id === '694555391467454525') // ID de notre channel
    var embed = new Discord.RichEmbed()
    .setColor('#76D880')
    .setDescription(`:inbox_tray: :tada: <@${member.user.id}> Bienvenue sur le serveur de AlexTheKing !!`)
    return welcomechannel.send({embed})

    });

  client.on('guildMemberRemove', member => {

      const welcomechannel = member.guild.channels.find(c => c.id === '694555391467454525') //ID de notre channel
      var embed = new Discord.RichEmbed()
      .setColor('#76D880')
      .setDescription(`:inbox_tray: :sob: <@${member.user.id}> nous a quitté !! `)
      return welcomechannel.send({embed})

    });

    client.login('TOKEN')

Ce que je veux

Je voudrais que mon bot se lance

Ce que j'obtiens

Mon erreur :
root@localhost:~/AlexBot# node alex.js
/root/AlexBot/alex.js:10
if(message.content === prefix + "info"){
^

ReferenceError: message is not defined
at Object.<anonymous> (/root/AlexBot/alex.js:10:3)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3

Pouvez vous m'aidez ? Je vous remercie d'avance !
Alexandre

1 réponse


Shizey
Réponse acceptée

Salut, il te manque l'event on Message

const Discord = require('discord.js');
const client = new Discord.Client();
var prefix = "/";

client.on("ready", () => {
    client.user.setActivity("Le Bot de AlexTheKing !");
    console.log('Prets !');
  }); 

client.on('message', message => {
  if (message.content === '/pay') {
    message.reply('Fait un dons sur paypal ! https://www.paypal.me/gael47 :wink: ')
  };

  if (message.content === '/site') {
    message.reply('https://animacraft.fr')
  };

  if (message.content === '/youtube') {
    message.reply('La chaîne youtube de AlexTheKing : https://www.youtube.com/channel/UCKoNqCns-6rmZRQV2MLrrZw ')
  };

  if (message.content === '/avatar') {
    message.reply(message.author.avatarURL);
  }

  if(message.content === prefix + "info"){
    var info_embed = new Discord.RichEmbed()
    .setColor("#DC143C")
    .setTitle("Les informations de mon Bot et du Serveur !")
    .addField(" :robot: Nom :", `${client.user.tag}`, true)
    .addField("Tag du bot :hash:", `#${client.user.discriminator}`)
    .addField(":id: ", `${client.user.id}`)
    .addField("Tu veux soutenir AlexTheKing ?", " https://www.paypal.me/gael47 :wink: ")
    .addField("Pour voir les commandes du bot :", " /commandes ")
    .addField("Nombre de Membres", message.guild.memberCount)
    .addField("En développement par AlexTheKing", "AlexTheKing")
    .setFooter("Info - Bot")
    message.channel.send(info_embed);
    console.log("Info");
};

if(message.content === prefix + "commandes"){
    var info_embed = new Discord.RichEmbed()
    .setColor("#DC143C")
    .setTitle("Les commandes du bot!")
    .addField("/youtube", " Récuperer le lien de la chaîne YouTube")
    .addField("/avatar", "Voir votre avatar")
    .addField("/pay", "Faire un dons !")
    .setFooter("Commandes - Bot")
    message.channel.send(info_embed);
    console.log("Commandes");
  };
});

  client.on('guildMemberAdd', member => {
    const welcomechannel = member.guild.channels.find(c => c.id === '694555391467454525') // ID de notre channel
    var embed = new Discord.RichEmbed()
    .setColor('#76D880')
    .setDescription(`:inbox_tray: :tada: <@${member.user.id}> Bienvenue sur le serveur de AlexTheKing !!`)
    return welcomechannel.send({embed})

    });

  client.on('guildMemberRemove', member => {

      const welcomechannel = member.guild.channels.find(c => c.id === '694555391467454525') //ID de notre channel
      var embed = new Discord.RichEmbed()
      .setColor('#76D880')
      .setDescription(`:inbox_tray: :sob: <@${member.user.id}> nous a quitté !! `)
      return welcomechannel.send({embed})

    });

    client.login('TOKEN')