使Discord js bot制作一个包含代码/ txt的文件

时间:2018-06-30 02:55:54

标签: bots discord discord.js

我想知道我有一个eval命令,有时输出文本太长了,我想知道如何将输出放入机器人制作的可下载文件中。

这是评估代码https://hastebin.com/etisujoneq.js,您能告诉我如何做/添加它吗?如果我想再次使用它,可以给我一般的代码。

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



module.exports.run = async (client,message,args) => {
    let role = message.guild.roles.find(r => r.name === "BanBot");
    if(message.member.roles.has(role.id)) return message.channel.send("Can not use this commnad!");
    var kitty = message.guild.members.find("id", "131417543888863232");
    if (message.member !== kitty)return message.channel.send("**Hey, `" + message.author.username + "` You Can't use eval only spoodercraft can!**");

const clean = text => {
  if (typeof(text) === "string")
    return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
  else
      return text;
}
//
if(!message.member.hasPermission("VIEW_AUDIT_LOG")) return message.channel.send("No permissions!");
//


    try{
      const code = args.join(" ");
      let evaled = eval(code);

      if (typeof evaled !== "string"){
        evaled = require("util").inspect(evaled);
      }

    if (evaled.includes(client.token)){
        evaled = evaled.replace(client.token, "THATS MY PRIVESSEESEES NO! AND I MEAN NO! \n\ YOU GET I WILL CALL THE COPS ");

        if (evaled.includes(client.token)){
            evaled = evaled.replace(client.token, "THATS MY PRIVESSEESEES NO! AND I MEAN NO! \n\ YOU GET I WILL CALL THE COPS ");
        }   
    }

    let embed = new Discord.RichEmbed()
    .addField(`Input`, "***```" + code + "```***", true)
    .addField(`Output`, `\`\`\`python\n${evaled}\`\`\``,)
    .setColor("#cb36ed")//
    .setTimestamp()



message.channel.send(embed).then(msg => {msg.delete(25000)});

    } catch (err) {
    message.channel.send('``Error``\n ```'+ clean(err) +'```').then(msg => {msg.delete(25000)});
    }    
}
module.exports.help = {
    name: "eval"
}

我查看了discord.js并进行了很多查找,但我不知道。

感谢您对我的帮助:D

1 个答案:

答案 0 :(得分:0)

检查webView是否大于2000(或更小)。

我觉得更好的方法是让它创建一个hastebin,因为您可以发送hastebin链接,这样可以节省您的时间。

您可以使用https://www.npmjs.com/package/hastebin-gen创建hastebin,然后使用返回的r变量作为链接。

伪代码

<string>.length