Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

module - How do I make an embedded argument?

whenever i type $effect [pokemon type], I want to be able to see the embeds I made for that specific pokemon. For example, $effect fire would show the effects of the fire with the embed message. Do I do args and then put the args = command so the arguments would be written as the pokemon type rather than args[0]? If so, how would I make the embeds appear? Because module.exports is not working whatsoever. Please be specific with your answers more than usual! I have a hard time understanding these things such as placement and commands as I'm new. Any point to the right direction is appreciated though! Here's the code and where they're set!:

bot > index.js

const Discord = require("discord.js");

const fs = require("fs");

// Change the prefix
const prefix = "$";
const client = new Discord.Client();

client.commands = new Discord.Collection();

const commandFiles = fs
  .readdirSync("./features/")
  .filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
  const command = require(`./features/${file}`);

  client.commands.set(command.name, command);
}

client.once("ready", () => {
  console.log("This bot is online!");
});

client.on("message", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) {
    return;
  }

  // Destructure the first word from message.content, leave the rest as an array
  const [commandName, ...args] = message.content
    .slice(prefix.length)
    .split(/ +/);

  // Attempt to get command by name from the Collection
  const command = client.commands.get(commandName.toLowerCase());

  if (!command) {
    return; // do something
  }

  command.execute(message, args);
});

client.login('token');

bot > features > effembeds.js

const { MessageEmbed } = require("discord.js");

module.exports.fairyEmbed = new MessageEmbed()
    .setColor('#dd525d')
    .setTitle('Fairy')
    .setURL('https://youtu.be/0K6qBmnRizU')
    .setDescription('Fairy types are too cutesy for my preference. They’re weak to Poison and Steel type and Fire, Steel and Poison types resist their attacks. But they do a lot of damage to Dark, Fighting and Dragon types. Dragon type attacks don’t effect them at all, so they’re good in that department.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.pinterest.com%2Fpin%2F627055948095995745%2F&psig=AOvVaw1Vu5xwOk0k9tBEJ9Yclz2F&ust=1609622152653000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCICQ3vXT--0CFQAAAAAdAAAAABAD')

module.exports.fightingEmbed = new MessageEmbed()
    .setColor('#61dde6')
    .setTitle('Fighting')
    .setURL('https://youtu.be/FJgRlbjzsrs')
    .setDescription('Fighting types are very resilient. Their attacks are super effective against Rock, Steel, Dark, Normal and Ice types and they resist Dark, Rock and Bug type attacks. Fighting type attacks won’t do well against Flying, Psychic, Fairy, Poison or Bug types and they won’t do anything to Ghost types and they’re very weak to Fairy, Psychic and Flying type attacks.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fpokemon.fandom.com%2Fwiki%2FZamazenta_(anime)&psig=AOvVaw1b8V8kCknIyef2c_zxuFjV&ust=1609622421791000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJCsvPXU--0CFQAAAAAdAAAAABAM')

module.exports.steelEmbed = new MessageEmbed()
    .setColor('#ba2838')
    .setTitle('Steel')
    .setURL('https://youtu.be/I_57ptO3TKc')
    .setDescription('Steel types are the prime definition of defense with an amazing resistance to Normal, Grass, Ice, Flying, Psychic, Bug, Rock, Dragon, Steel and Fairy type attacks and are immune to Poison attacks. They’ll do immense damage to Rock, Fairy and Ice types. If they get hit by Fire, Ground or Fighting type attacks, they’ll be greatly damaged and they don’t do much to Water, Fire, Electric or other Steel types.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fpokemongohub.net%2Fpost%2Fguide%2Fdialga-heat-map%2F&psig=AOvVaw3l68mb5ltZZZusGgHSGLTd&ust=1609622768057000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKjLpZ_W--0CFQAAAAAdAAAAABAV')

module.exports.darkEmbed = new MessageEmbed()
    .setColor('#3a4c7b')
    .setTitle('Dark')
    .setURL('https://youtu.be/0K6qBmnRizU')
    .setDescription('Dark type Pokémon are masters of the night and dirty, underhanded tactics. They’re very strong against Psychic and Ghost and resist Dark and Ghost type attacks. Psychic type attacks don’t stand a chance due to their immunity. It’s best to avoid putting them against Fighting, Fairy and Bug type attacks because of their weakness and they won’t do as much damage against Dark, Fighting and Fairy type Pokémon. Either way you slice it, Dark type Pokémon are very strong. Spikemuth’s gym is a prime example of that.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fbulbapedia.bulbagarden.net%2Fwiki%2FYveltal_(Pok%25C3%25A9mon)&psig=AOvVaw01HxoY93uTikkUD-yDrdJU&ust=1609623455517000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIDG2OLY--0CFQAAAAAdAAAAABAD')

module.exports.dragonEmbed = new MessageEmbed()
    .setColor('#352822')
    .setTitle('Dragon')
    .setURL('https://youtu.be/8lrMjcNJGfE')
    .setDescription('Dragon types are very rare and thought to be a mystical type. If you want to stop them in their tracks, use Fairy, Ice or Dragon type moves against them. Dragon types resist Fire, Water, Grass and Electric type attacks and Dragon Type attacks are only strong against themselves but have a wide variety of attacks. Dragons type moves don’t do much to Steel types and Fairy types are completely immune to their attacks. My bro said Raihan was infamous for completely demolishing trainers with his overwhelming dragons, so I’d watch your choices around them.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fbleedingcool.com%2Fgames%2Frayquaza-raid-guide-how-to-catch-a-shiny-rayquaza-in-pokemon-go%2F&psig=AOvVaw02L1u59NkP3kqQSp5xAJKB&ust=1609623775222000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCIiX9PvZ--0CFQAAAAAdAAAAABAD')

module.exports.groundEmbed = new MessageEmbed()
    .setColor('#000000')
    .setTitle('Ground')
    .setURL('https://youtu.be/5V0kzLYkYTM')
    .setDescription('Ground types are masters of the surface and underneath the ground. They’re super effective against Poison, Steel, Rock, Fire and Electric types. They resist Rock and Poison type attacks and are immune to Electric attacks. If they get his by Grass, Water or Ice type attacks, they’ll be greatly damaged. Bug and Grass types resist their attacks and Flying types are completely immune to them.')
    .setThumbnail('https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.zedge.net%2Fwallpaper%2F23b8d5ed-9f57-39e7-b27c-ffd2df026702&psig=AOvVaw3xIwv-YzXf8AuUEaTGfBp4&ust=1609622014464000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDrk7TT--0CFQAAAAAdAAAAABAJ')
    .setImage('https://www.google.com/url?sa=i&url=https%3A%2F%2Fpokemondb.net%2Fpokedex%2Fgroudon&psig=AOvVaw0dkrbkk1pp7Q7h5WqwkTk8&ust=1609711340636000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCMDg-5eg_u0CFQAAAAAdAAAAABAJ')

bot > features > effectcmds.js

const { effect } = require("./effembeds.js"); // Change the file import based on where it is located

module.exports = {

  name: "effect",

  description: "information on effects from pokke!",

  execute(message, args) {
//POKEMON TYPE -- FAIRY
    if(command === 'fairy'){
      module.exports = fairyEmbed;
      }
//POKEMON TYPE -- FIGHTING
    if(command === 'fighting'){
      module.exports = fightingEmbed;
    }
//POKEMON TYPE -- STEEL
    if(command === 'steel'){
      module.exports = steelEmbed;
      }
//POKEMON TYPE -- DARK
    if(command === 'dark'){
      module.exports = darkEmbed;
      }
//POKEMON TYPE -- DRAGON
    if(command === 'dragon'){
      module.exports = dragonEmbed;
      }
//POKEMON TYPE -- GHOST
    if(command === 'ghost'){
      module.exports = ghostEmbed;
    }
//POKEMON TYPE -- PSYCHIC
    if(command === 'psychic'){
      module.exports = psychicEmbed;
    }
//POKEMON TYPE -- ROCK
    if(command === 'rock'){
      module.exports = rockEmbed;
    }
//POKEMON TYPE -- BUG
    if(command === 'bug'){
      module.exports = bugEmbed;
    }
//POKEMON TYPE -- FLYING
    if(command === 'flying'){
      module.exports = flyingEmbed;
    }
//POKEMON TYPE -- GROUND
    if(command === 'ground'){
      module.exports = groundEmbed;
    }
//POKEMON TYPE -- POISON
    if(command === 'poison'){
      module.exports = poisonEmbed;
    }
//POKEMON TYPE -- ICE
    if(command === 'ice'){
      module.exports = iceEmbed;
    }
//POKEMON TYPE -- GRASS
    if(command === 'grass'){
      module.exports = grassEmbed;
    }
//POKEMON TYPE -- ELECTRIC
    if(command === 'electric'){
      module.exports = electricEmbed;
    }
//POKEMON TYPE -- WATER
    if(command === 'water'){
      module.exports = waterEmbed;
    }
//POKEMON TYPE -- FIRE
    if(command === 'fire'){
      module.exports = fireEmbed;
    }
//POKEMON TYPE -- NORMAL
    if(command === 'normal'){
      module.exports = normalEmbed;
    }
//POKEMON TYPE -- ALL
    if(command === 'all'){
      module.exports = allEmbed;
    }
console.log(args[0]);

 },
};
question from:https://stackoverflow.com/questions/65545500/how-do-i-make-an-embedded-argument

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

module.exports is working but you understood it wrong. It is there to use specific functions etc., or in your case Embeds, everywhere you need it. So you just have to update your effectcmds.js into:

const effect = require("./effembeds.js"); // Change the file import based on where it is located

module.exports = {

  name: "effect",

  description: "information on effects from pokke!",

  execute(message, args) {
//POKEMON TYPE -- FAIRY
    if(args[0] === 'fairy'){
      message.channel.send(effect.fairyEmbed);
      }

   //Edit that for every embed!

args is an array that stores your input after your prefix. So args[0] is the first input after your prefix. This is okay for this case, because every effect is only one word.

You can send the embed simply using the variable, where you stored the location of the embed file. As you can see in my example it is effect.fairyEmbed for the input fairy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...