我如何制作它以便我可以调用另一个文件的嵌入并将其发布?

如何解决我如何制作它以便我可以调用另一个文件的嵌入并将其发布?

这是我的 index.js: (bot > index) 索引是主文件。这不是我要问的主要焦点,但也许错误可能源于这里。

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

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

client.commands = new Discord.Collection();

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

for (const file of commandFiles) {
  const command = require(`./commands/${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(/ +/);


  const command = client.commands.get(commandName.toLowerCase());

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

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

client.login("token")

;

这是我的 effect.js: (bot > commands > effect) 这通常是错误代码的来源。这更像是一个专门用于 Pokemon 效果的命令子文件夹。这特别给了我最难实现的目标,因为我不知道如何将代码发送到另一个文件中,同时又不限制它。我的目标很简单:使嵌入消息没有垃圾代码。

//REMINDER: PREFIX IS $
  //RESET BOT TERMINAL CODE: NODE .

module.exports = {
  name: "effect",description: "Information on Pokemon!",execute(message,args) {
    // args[0] would be the second word from message.content
    // You should check if they used the command the right way
    // $effect some-type would make args[0] some-type
    var command = args[0]
    var channel = 0x792853588388872202

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

这是我的 effect-embed.js:(与 effect.js 相同)又名问题 #2。这是 embeds 本身所在的地方。我不知道如何在不复制和粘贴的情况下传输它们,所以我在这里。

// inside a command,event listener,etc.
const Discord = require("discord.js");

const fairyEmbed = new Discord.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')
message.channel.send({embed: fairyEmbed});

const fightingEmbed = new Discord.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')

const steelEmbed = new Discord.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,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')

const darkEmbed = new Discord.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')

const dragonEmbed = new Discord.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')

const ghostEmbed = new Discord.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,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。我给你举个例子:

module.exports = darkEmbed;

然后您将在其他文件中导入 darkEmbed。

const { darkEmbed } = require("file")

存在 { } 是因为嵌入文件中有多个对象。

,

您可以在 module.exports 文件中使用 effect-embeds.js,并在 effect.js 文件中使用它。

例如

// effect-embeds.js

module.exports.effect = new Discord.MessageEmbed()
    //embed information

// Compared to (DO NOT DO)
const effect = new Discord.MessageEmbed()
    //embed information

然后在您的其他文件中...

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

channel.send(effect);

此外,不要反复使用 if 语句

if(...) {
  //code
}

使用 switch

switch(command) {
   case '...':
      // code
   break;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res