Tuesday, 25 April 2017

Show SQL value using Node

I'm using Node.js to create a Discord Bot. I want to display all the custom commands when a user types !commands all, the Table looks as follows

| | guildname | guildid | commandname | commandreply | username | userid
------------------------------------------------------------------------
| | MyServer    1002      !test         This is test   Rusty      890

I have got this code:

var info = {
  "guildname": message.guild.name,
  "guildid": message.guild.id,
  "commandname": args[0],
  "commandreply": args.join(" ").slice(args[0].length),
  "username": message.author.username,
  "userid": message.author.id
}

connection.query("SELECT * FROM commands WHERE guildid = '" + message.guild.id + "'", info, function(error, commandExists) {
  if (error) throw error;

  if (commandExists.length) {
    console.log(commandname); // commandname is not defined
  }
}

How do I access one of those values, for example, the commandname?



via Rusty

No comments:

Post a Comment