share
Stack OverflowHow can you get the serverinfo in your second args?
[0] [1] user12507447
[2020-04-29 22:32:33]
[ javascript node.js discord.js ]
[ https://stackoverflow.com/questions/61512865/how-can-you-get-the-serverinfo-in-your-second-args ]

So I have a serverinfo command that shows your server info but I would like to get also other servers info by using the server id in your 2nd args. But it shows only mine and even if I have a 2nd args it does the same.

const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {


  var Guild = message.guild + bot.guilds.get(args[1])
  var Myguild = message.guild;

  if (!args[1] == null)

    message.channel.send("Invallid")


  var embed = new Discord.RichEmbed()
    .setColor("#c59c16")
    .setAuthor(Myguild.name, Myguild.iconURL || Guild.name, Guild.iconURL)
    .setThumbnail(Myguild.iconURL || Guild.iconURL)
    .addField("Name", Myguild.name || Guild.name, true)
    .addField("Owner", Myguild.owner || Guild.owner, true)
    .addField("Region", Myguild.region || Guild.region, true)
    .addField("ID", Myguild.id || Guild.id, true)
    .addField("Members", Myguild.memberCount || Guild.memberCount, true)
    .addField("Bots", Myguild.members.filter(member => member.user.bot).size || Guild.members.filter(member => member.user.bot).size, true)
    .addField("Voice channels", Myguild.channels.filter(chan => chan.type === 'voice').size || Guild.channels.filter(chan => chan.type === 'voice').size, true)
    .addField("Text channels", Myguild.channels.filter(chan => chan.type === 'text').size || Guild.channels.filter(chan => chan.type === 'text').size, true)
    .addField("Roles", Myguild.roles.map(r => r.name).join(" , ") || Guild.roles.map(r => r.name).join(" , "))
    .setFooter("Created: " + Myguild.createdAt || Guild.createdAt)
  message.channel.sendEmbed(embed);
}


module.exports.help = {
  name: "serverinfo"
}
[0] [2020-04-29 23:34:41] Syntle

that's because you're using the + operator instead of || operator, your Guild variable needs to be replaced with var Guild = message.guild || bot.guilds.get(args[1])


It now says --> (node:15404) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.author.icon_url: Not a well formed URL. - user12507447
Because you need to use Myguild.iconURL() - Syntle
If my answer has solved the issue you mentioned in the question, then accept it to let others know what worked - Syntle
.setAuthor(Myguild.name, Myguild.iconURL() || Guild.name, Guild.iconURL()) .setThumbnail(Myguild.iconURL() || Guild.iconURL()) I add a () to iconURL but it now says that it's not a function - user12507447
Oh my bad sorry, I just woke up, Myguild.iconURL is right but it says it's not a well formed URL, that's caused by the fact you tried using the Guild.name as a URL value, you need to remove Guild.name + leave it as Myguild.iconURL || Guild.iconURL - Syntle
It now only works in the server I currently am and By server name it's null because I deleted the .name. So what I want is if I use the command $serverinfo it shows the server info where I am now but I want also to do $serverinfo id that shows the server info of that id I have written in the first args. - user12507447
1