Discord x Hastebin command doesn't behave as intended

848 Views Asked by At

So I'm trying to make a bot that posts given data to hastebin. But it doesn't really behave well. I'm using discord.js and hastebin-gen.

This is the code:

const hastebin = require('hastebin-gen');
exports.run = (client, msg, args) => {
    let haste = args.slice(0).join(" ")
    let type = args.slice(1).join(" ")
    if (!args[0]) { return msg.channel.send("Usage: bin.haste yourmsghere.") }
        hastebin(haste, type).then(r => {
        msg.channel.send(":white_check_mark: Posted text to Hastebin at this URL: " + r);
    }).catch(console.error);
}

When ran, for example bin.haste this code is awesome, it returns this:(https://a.pomf.cat/rkjqog.png) (Note: Can't post images yet, sorry.)

If I click on the link, it successfully uploads the text given to Hastebin: (https://a.pomf.cat/ovcpzb.png)

But there's just that annoying fact that it repeats the given text, as seen at the end of the link, and after the link.

1

There are 1 best solutions below

0
On BEST ANSWER

What it's adding is the extension you're passing to hastebin-gen. Don't pass one and it will just respond with the link.

Hastebin-gen only adds the extension to the link at this line:

res("https://hastebin.com/" + body.body.key + ((extension) ? "." + extension : ""));

The extension doesn't matter at all, hastebin.com/beqojuzowe.jhffyjbfft will point to the same as hastebin.com/beqojuzowe.

TL;DR use this:

hastebin(haste).then(r => {