How Do These Examples Work?
Each example is a small piece of a Discord bot written with discord.js. They all share this helper, which sends a request with your token and throws if it fails:
Store your token in the MELONLY_TOKEN environment variable. See Authentication.
Find the Staff Member Behind a Command
Writes run as a staff member, so most commands start by turning the Discord user who ran them into a member ID. See How Writes Work.
If the person isn't in your Melonly server, this throws member not found. That's a good point to tell them they're not staff.
Log a Punishment From a Slash Command
A /warn command that creates a warning as the moderator who ran it. Melonly posts it to your log channel and DMs the player, just like the Mod Panel.
Use type: 1 for a kick and type: 2 for a ban. For your server's custom types, get the typeId from List Log Types and send it with type: 5.
Start and End Shifts With Buttons
Two buttons that start and end the clicker's shift. Discord shift roles, nickname prefixes and your shift channel all update as usual.
If the member is already on shift, the API returns a 409 and melonly throws, so wrap the calls in try and reply with error.message like the /warn example.
Show Who's on Shift
A /onshift command that lists everyone currently on shift.
Look Up a Player's Record
A /record command that shows a player's recent logs. Looking them up by Roblox ID also finds logs from before they changed their username.
Where to Go Next
Need help?
Still have questions? Join our Discord server for support from the Melonly Team.