Skip to content

Project 1 - Making a Discord bot

Created: 2020-02-18 11:32:31 -0800 Modified: 2020-02-21 12:20:03 -0800

  • I’m relying on the Twitch and Patreon integrations to properly apply their respective roles, that way I can fetch all users’ roles at start-up and then only have to listen to the webhook for role changes. This makes it so that I don’t need a setInterval or something to occasionally cache role information.
    • Update: apparently the Patreon bot is not reliable according to Melmsie (DankMemer’s creator).
  • I don’t ever account for tier values/perks changing.
  • I don’t want people’s perk information to be public, so I couldn’t use roles automatically assigned by Patreon. Even if I could have done this, I think I would still have needed to connect to Twitch since they only assign a role of “subscriber” instead of differentiating between tiers.
  • The reason I did such a circuitous method of connecting Discord to Twitch is so that users don’t have to go through an intermediate OAuth page. There is an API to fetch a user’s connections, but it requires the “connections” scope (reference). Instead, I think it’ll be much cleaner for users to just get a DM with a whisper command and run that on Twitch.
  • I used tmi.js before realizing that the NPM module named “twitch” even exists, but apparently “twitch” also handles chat, so I suppose tmi.js could be removed.
    • Also, the chat client connects as AdamLearnsBot whereas I need the Helix client to connect as me so that it can fetch my subscriptions.
  • Users aren’t removed from the database when their subscriptions lapse because they may have set perk information that they’ll want later. For example, maybe they subscribe in January, set a shout-out name, then subscribe again in June; we shouldn’t delete their shout-out name.
  • A user’s voting power can change if their Twitch or Patreon subscription level changes (including losing their subscription). However, we don’t update corresponding polls immediately, only when they end. Polls can end while the bot is offline too, which is what led to the creation of the “has_closed” property on polls.