Official Glitch Discord Bot Starter!

Hi everyone! We just released a an Official Glitch Discord Bot starter. It has an interactive install guide that will teach you what you need to know to get started with your first (or 100th) Discord Bot on Glitch:

It comes with a video that will help you get started!

Please check it out and we’d love your feedback. We’ve also created some remixes of it that provide demos of what you can do with it. We’re happy to create more if you have an example you’d like us to show you how to make:

5 Likes

Looks huge, great job :slight_smile:

What is the purpose of the bot being able to create monitors on uptime robot?

2 Likes

the bot will be running forever (almost).

2 Likes

Why expose

router.get("/createMonitor", function(request, response)

to everybody? Anybody can spawn monitors without a consent of the owner.

Also the code is, uh, weirdly done(?).

let sender = message.user.toString();

you don’t need to call toString explicitly, when using string interpolation JS will do it on it’s own.

let recipient = message.mentions.users.filter(user => user.bot === false).array()[0].username;

why so?

You’re right about createMonitor, it has been removed thanks!

The last one you mention is pretty awkward, but I wasn’t sure how else to get around this issue:


Suggestions appreciated!

yeah, discord gives mentions in wrong order, but that’s not my concern.

.array()[0]

just call first() on collection instead of calling the array method and accessing it’s first element.
imo looks nicer and probably is more performant(?).

but uh- if you want to get the correct mention you probably should just parse the message using provided regex in message.mention property

Ah yes I agree. I found https://discordjs.guide/miscellaneous/parsing-mention-arguments.html#using-regular-expressions and will implement it soon and also link to it.

2 Likes

I did a quick benchmark on this.
functions i’ve used were taken from that guide’s repo.
https://jsperf.com/regex-vs-default (don’t mind the name)

but tl;dr
native implementation happened to be fastest.

regex with length checking

/^<@!?(\d{18})>$/

was about 20% slower (but it’s pretty readable)

and regex from that guide

/^<@!?(\d+)>$/

happened to be slowest of all and it’ll be failing on edge cases like <@1>

Thanks! When I have time I’ll dive in but these are great leads.

BTW if anyone wants to contribute here is our official github repo:

2 Likes

Cool project & video. Just wondering why you chose to use Botkit instead of Discord.js, etc.

:slight_smile: Have a great day.

Botkit is just a wrapper for Discord.js

Yep, it has both Discord.js and Botkit (since the Botkit Discord depends on Discord.js). It’s possible I will refactor in the future as Botkit has a new version out that may not be as compatible with Discord.

There are a lot of things I like in Botkit like:

  • Storage connectors- makes it easier to swap out databases
  • Syntax - I like how readable the code is
  • Documentation- I think the documentation is easier to understand than the Discord.js is, but that’s just a personal opinion
2 Likes

Hey I’m sorry for the dumb question I’m new to all this stuff. How would you add a second command to the bot?

Hi! You can copy the code block with .hears. There is an example here:

Hope that’s helpful, lemme know if you have any other questions!

@mmcewen How do I let the bot use ambient?

@Swiftammer422 have you tried pancake. Very forward.

What’s pancake? I need this to be 20 characters to post so I’m adding extra words

In your .hears method, the second parameter allows you to set the context of when a handler is executed.
ie:
discordBot.hears('noodles', 'ambient', (bot, message) => bot.reply('pho noodles!'));

If you want your hears to support across different contexts, just use an array like such: [‘ambient’, ‘direct_message’]

So whenever the bot hears noodles in any message within a thread it’s in, it will respond with pho noodles!

too bad people dont know how to eris

1 Like

eris is good and botkit is just discordjs dumbed down to the point it makes you look like you add spaces before marks

1 Like

Hi everyone, I made some changes based on some feedback from some folks at discord.js

I may make an eris version in the future, it sounds very interesting.

Also here’s an example of usage of ambient https://glitch.com/edit/#!/honk-honk?path=skills/hears.js:14:8

I was thinking about recreating the botkit for eris.

I’ve been trying to work out how to use the Conversations feature of Botkit in this example - either I get no responses or I crash the application.

Anyone have a working, minimal example of asking a question and acting on the response using Conversations (rather than doing all the parsing myself)?

Interesting question, I don’t see any references to it in the BotKit Discord code:


You might want to file an issue there. If I have time I’ll try to make it work myself but my instinct is that I might have to contrib code to botkit-discord to make it work.

It’s in the “Advanced Usage” section of the readme for Botkit-Discord, for example convo.AddQuestion and convo.say are both parts of the conversations API in Botkit.

bot.createConversation(message, (err, convo) => {
				convo.addQuestion('How would rate that from a scale of 0 to 5?', (response, convo) => {
					const numberRating = response.text.match(/[0-5]/g);
					if (numberRating.length < 1) {
						convo.say('Uhh... not a valid rating, try again later!');
						convo.next();
					}
					convo.say('Oh wow! Thanks for letting me know!');
					db.save(message.member.id, numberRating[0]);
					convo.next();
				});
			});

Hey, how can i activate my bot without saying @botnamehere?

If you set up the .hears() function adding “ambient” to the list it will respond anytime it hears the keywords - codingbyhim posted an example above on Sep 19