npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-bot0920

v1.0.0

Published

Follow these instructions after deploying this repo on Cyclic.sh

Downloads

4

Readme

starter-discord-bot

Follow these instructions after deploying this repo on Cyclic.sh

Deploy to Cyclic

Set-up and configuration

1. Create discord application

Navigate to Discord's developer portal and create a new application

  • https://discord.com/developers/applications

2. Get application keys and parameters

After creating the application, you are taken to the application's dashboard. There you can configure an app icon, description, etc.

Retrieve:

  • APPLICATION ID (Discord also calls this CLIENT ID)
  • PUBLIC KEY

Configure your Cyclic App with these environment variables.

3. Enable the Bot in the application

On the left hand side, go to Bot then click on Add Bot

You will need to create the bot token. Press Reset Token and confirm.

Retrieve the TOKEN string and configure your Cyclic App with this environment variable.

4. Adding the bot to your server

The easiest way to add the bot to your server is via url.

Go to OAuth2 > URL Generator on the left, select the permissions:

  • applications.commands - allows you to register slash commands
  • bot - this will show additional permissions for the bot
    • Send Messages - to allow the bot to send messages

Copy and navigate to the generated URL at the bottom.

The page will ask you to select a server to install your bot on, it will go through a few prompts to verify that you are human.

After you authorize, the bot will appear in your server.

Keep in mind, the bot does not yet have any code running, so it will not do anything just yet

5. Get your Server ID

To get the server id (Discord also calls this GUILD ID), you first have to enable developer mode for in your discord user settings > advanced:

With developer mode on, you will be able to right click the discord server name to copy it's id:

Developer mode allows you to right click all kinds of things in discord to get their id's (channels, users, messages, etc.)

6. Set up environment variables

At this point, make sure you've collected all the variables you will use in your environment

  • CLIENT_ID (same as Application ID)
  • PUBLIC_KEY
  • TOKEN
  • GUILD_ID (same as Server ID)

Set up interactions endpoint

This step is VERY IMPORTANT, it lets discord know the url at which the bot is running. Discord will send interaction event payloads to this endpoint.

When you first enter the endpoint into the ui, discord will make a cryptographically signed request to your endpoint and expect you to verify the signature. This will establish trust between discord and your hosted bot.

  1. Make sure your bot is deployed to Cyclic
  2. Before entering the endpoint make sure the environment variables have been properly configured and that process.env.PUBLIC_KEY is set.
  3. Enter the your Cyclic App url as the endpoint url into discord and Save Changes (eg https://[your bot's url].cyclic.app/interactions)
  • The /interactions endpoint is using the verifyKeyMiddleware function to verify the keys automatically
app.post('/interactions', verifyKeyMiddleware(PUBLIC_KEY), async (req, res) => {
    ...

Register slash commands

  1. Make sure all of the environment variables have been correctly set up
  2. Go to https://[your bot's url].cyclic.app/register_commands This route makes a put request to register two commands on your server: /yo and /dm app.get('/register_commands', async (req,res) =>{

Refer to the discord docs to extend this further

After registering commands, you should see them available in your discord server

Try the bot!

In any channel type /yo or /dm.

NOTE: this starter does not configure

/yo

/dm