Discord 如何异步运行commands文件夹中的命令文件

Discord 如何异步运行commands文件夹中的命令文件,discord,discord.js,Discord,Discord.js,我想给我的discord机器人添加一个kick命令,它使用wait函数 client.on("message", async (message) => { 但是,我无法在commands文件夹中的命令文件中执行此操作 我的踢腿命令 const { MessageEmbed } = require("discord.js"); module.exports = { name: "kick", description: &

我想给我的discord机器人添加一个kick命令,它使用wait函数

client.on("message", async (message) => {
但是,我无法在commands文件夹中的命令文件中执行此操作 我的踢腿命令

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

module.exports = {
  name: "kick",
  description: "kicks a member",
  execute(client, args) {

    if (!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send("Invalid Permissions")
    let member = message.mentions.members.first()
    if(!member)
      return message.reply("Please mention a valid member of this server");
    if(!member.kickable) 
      return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
    
    let reason = args.slice(1).join(' ');
    if(!reason) reason = "No reason provided";
    
    await member.kick(reason)
      .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
    message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`)
    }}

抱歉,如果这似乎是一个愚蠢的问题,我对编码相当陌生

尝试将代码更改为:

module.exports={
名称:“踢”,
描述:“踢一个成员”,
//这条线换了vvv
//这条线换了vvv
//这条线换了vvv
执行:异步(客户端,参数)=>{
if(!message.member.hasPermission(“KICK_MEMBERS”))返回message.channel.send(“无效权限”)
让member=message.notices.members.first()
如果(!成员)
返回消息。回复(“请提及此服务器的有效成员”);
如果(!member.kickable)
返回消息。回复(“我不能踢这个用户!他们有更高的角色吗?我有踢权限吗?”);
让reason=args.slice(1.join)(“”);
如果(!reason)reason=“未提供原因”;
等待成员。踢(原因)
.catch(error=>message.reply(`Sorry${message.author}我无法启动,因为:${error}`));
message.reply(${message.author.tag}已踢出“${member.user.tag}”,因为:${reason}`)
}}
具体变化:
execute(客户端,参数){
变成
execute:async(客户端,参数)=>{

从本质上讲,它说函数是异步的,而您的代码只是将execute声明为普通(sync)函数。另外,由于我不确定您是否可以使用普通函数语法声明异步函数,因此我将其更改为ES6 arrow函数语法: 例如,
execute(){}
to
execute:()=>{}

您可以阅读有关箭头函数的更多信息

如果可能,是否可以提供有关命令如何工作的更多信息。在主文件中使用什么代码来解释该命令?const commandFiles=fs.readdirSync('./commands/').filter(file=>file.endsWith('.js');for(commandfileofcommandfiles的const file){const command=require(
/commands/${file}
);client.commands.set(command.name,command);};啊,是的,我试过这么做,但我不知道我应该放箭头,非常感谢