久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

discord.js 列出我所有的機器人命令

discord.js list all my bot commands(discord.js 列出我所有的機器人命令)
本文介紹了discord.js 列出我所有的機器人命令的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用 discord.js 制作了一個不和諧機器人,并嘗試執行幫助命令向用戶顯示所有可用命令.

i made a discord bot with discord.js and tried to do a help command to show the user all available commands.

示例命令:avatar.js

module.exports.run = async(bot, message, args) => {
    let msg = await message.channel.send("doing some magic ...");
    let target = message.mentions.users.first() || message.author;

    await message.channel.send({files: [
        {
            attachment: target.displayAvatarURL,
            name: "avatar.png"
        }
    ]});

    msg.delete();
}

module.exports.help = {
    name: "avatar",
    description: "show the avatar of a user",
    usage: "[@user]"
}

然后我嘗試發送帶有完整命令列表的消息,例如:

Then i tried to send a message with the complete list of the commands like:

  • 命令 1
  • 說明
  • 用法
  • 命令 2
  • 說明
  • 用法
  • ...

help.js

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

module.exports.run = async(bot, message, args, con) => {
    fs.readdir("./cmds/", (err, files) => {
        if(err) console.error(err);

        let jsfiles = files.filter(f => f.split(".").pop() === "js");
        if(jsfiles.length <= 0) {
            console.log("No commands to load!");
            return;
        }

        var namelist = "";
        var desclist = "";
        var usage = "";

        let result = jsfiles.forEach((f, i) => {
            let props = require(`./${f}`);
            namelist = props.help.name;
            desclist = props.help.description;
            usage = props.help.usage;
        });

        message.author.send(`**${namelist}** 
${desclist} 
${usage}`);
    });
}

module.exports.help = {
    name: "help",
    description: "show all commands",
    usage: ""
}

我的代碼有點工作,但它只發送第一個命令.

my code is kinda working but it only sends the first command.

我對 javascript 很陌生,我找不到解決方案.我試圖用谷歌搜索所有關于 foreach 地圖不和諧集合和東西的東西,但我找不到將結果組合在一起的例子.

Im pretty new to javascript and i can't find a solution to this. I tried to google everything on foreach maps discord collections and stuff but i cant find a example where the results get combined together.

如果有人可以幫助我或給我一個提示,我可以在哪里搜索類似的東西.會很棒.

If anybody can help me or give me a hint where i can search for something like this. Would be awesome.

推薦答案

你的代碼只發送一個命令的原因是你的代碼只調用 message.author.send('...' 一次.您成功地使用每個文件中的數據設置了變量 namelistdesclistusage,但您的 .forEach(... 循環只是在移動到下一個文件時覆蓋所有數據.

The reason your code is only sending the one command is because your code only calls message.author.send('...' once. You successfully set the variables namelist, desclist, and usage with data from every file, but your .forEach(... loop just overwrites all of the data when it moves to the next files.

嘗試在 .forEach(... 循環的每次迭代中發送數據,如下所示:

Try to send data inside each iteration of the .forEach(... loop like this:

var namelist = "";
var desclist = "";
var usage = "";

let result = jsfiles.forEach((f, i) => {
    let props = require(`./${f}`);
    namelist = props.help.name;
    desclist = props.help.description;
    usage = props.help.usage;

    // send help text
    message.author.send(`**${namelist}** 
${desclist} 
${usage}`);
});

這篇關于discord.js 列出我所有的機器人命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 性网站免费 | 91欧美精品成人综合在线观看 | 国产激情在线 | 99精品欧美一区二区蜜桃免费 | 国产精品区二区三区日本 | 久久久久国产一级毛片高清网站 | 日韩一区二区福利视频 | 欧美精品一区二区三区在线播放 | 国产一区二区在线免费观看 | h片免费在线观看 | 国产精品久久久久久久久久 | 一区二区三区电影在线观看 | 亚洲成人一区二区 | 99精品视频在线观看免费播放 | 午夜精品久久久久久久99黑人 | 一级黄色毛片免费 | 精品国产一区二区在线 | 成人a视频 | 亚洲免费视频在线观看 | 日韩国产在线 | 一区二区视频 | av毛片在线| 日韩电影中文字幕 | 国产精品久久久久久久久久久久久 | 国产精品片 | 欧美福利 | 午夜小视频在线观看 | 97精品超碰一区二区三区 | 午夜在线电影网 | 亚洲激情网站 | 日本三级日产三级国产三级 | 一本一道久久a久久精品蜜桃 | 一级毛片网 | 精品久久久久久久久久久 | 华人黄网站大全 | 久久久精品久久 | 日日夜夜天天久久 | 亚洲精品第一国产综合野 | 欧美综合一区二区三区 | 国产91色在线 | 亚洲 | 中文字幕精品视频在线观看 |