Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Booru is not a constructor? #40

Closed
synesthesium opened this issue Jan 14, 2020 · 4 comments · May be fixed by #50
Closed

Booru is not a constructor? #40

synesthesium opened this issue Jan 14, 2020 · 4 comments · May be fixed by #50
Assignees
Labels

Comments

@synesthesium
Copy link

so here's my code.

const Booru = require('booru') // load the fucking uhh
const sb = new Booru("sb")
const Discord = require('discord.js'); // make discord actually need discord.js
const client = new Discord.Client(); // make bot do a fucking exist
const prefix = "#"; // prefix what the fuck else to say
const version = "3.1 alpha";
const botname = "MSPABot";
const hostsys = "Debian 10 using Windows 10 Home"
const imgsfw = sb.search(['homestuck'])

client.on("message", (message) => {
// Exit and stop if it's not there
if (!message.content.startsWith(prefix)) return;

if (message.content.startsWith(prefix + "imgtest")) {
message.channel.send(botname + " " + version + " " + hostsys + "\n" + imgsfw[0].postView);
} else
if (message.content.startsWith(prefix + "foo")) {
message.channel.send("bar!");
}
});

client.login("mmm im not putting the token on git ;)");

every run though i get the following:

/home/saiko/MSPABot/main.js:2
const sb = new Booru("sb")
^

TypeError: Booru is not a constructor

clearly booru is a constructor. what

@AtoraSuunva
Copy link
Owner

It's an issue with how typescript is compiling the package, so instead of the intended new Booru('sb'), you need to use new Booru.default('sb')

I will see how I can force typescript to not do that (or expose a Booru.for('sb')), meanwhile you can use Booru.search('sb', tags)

@synesthesium
Copy link
Author

great, but now i get this (unrelated to bot code)

const Booru = require('booru'); // load the fucking uhh
const sb = new Booru.default("sb");
const Discord = require('discord.js'); // make discord actually need discord.js
const client = new Discord.Client(); // make bot do a fucking exist
const prefix = "#"; // prefix what the fuck else to say
const version = "3.1 alpha";
const botname = "MSPABot";
const hostsys = "Debian 10 using Windows 10 Home";
const imgsfw = sb.search(['homestuck'], {limit: 1});

client.on("message", (message) => {
// Exit and stop if it's not there
if (!message.content.startsWith(prefix)) return;

if (message.content.startsWith(prefix + "imgtest")) {
message.channel.send(botname + " " + version + " " + hostsys + "\n" + imgsfw[0].postView);
}
});

client.login("NO TOKEN HERE EHEHEH");

gives:
TypeError: cannot read property "postView" of undefined
should i put this in a separate issue?

@AtoraSuunva
Copy link
Owner

It's a separate issue, imgsfw is a Promise so you need to either await (inside an async function) or use .then()

AtoraSuunva pushed a commit that referenced this issue Feb 5, 2020
@AtoraSuunva
Copy link
Owner

booru@2.1.0 now exposes booru.fromSite(site), since Typescript doesn't really have a good way to get around booru.default that isn't just not using export altogether.

Let me know if that works for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants