Fancy Developer Info
Don't bother reading this if you don't code.
How Hoppi Works
Hoppi's Original Framework
const Discord = require('discord.js')
const client = new Discord.Client({ disableEveryone: false })
const prefix = ';'
client.on("ready", async () => {
console.log("Bot online")
// Console log when the bot is logged in
client.user.setActivity(prefix + "help", {
type: "WATCHING",
name: "online"
});
// Set bot status
}
client.on("message", async (message) => {
// Make sure this function is asynchronous, much of the Discord API is async.
if (message.author.bot) { return };
// this checks if the author is a bot
if (message.guild == null) {
return message.channel.send("If there is no message.guild it means the" +
" author direct messaged the bot.")
}
// this checks if the message is a dm and returns if it is.
if (message.content.indexOf(prefix) !== 0) { return };
// this checks if the message starts with the prefix, you can also use message.content.startsWith(prefix).
const args = message.content.toLowerCase().slice(prefix.length).trim().split(' ');
// toLowerCase() makes the string lowercase.
// slice(prefix.length) slices the prefix off the string so I don't have to deal with it later.
// trim() trims the spaces off the string at the beginning and end, if it has any.
// split(' ') splits the string on spaces, so args becomes an array of each word of their message.
const command = args.shift()
// this makes command become the first value in args, so the first word of their message.
// Now that the checks are done, we can check what command their message is.
// DISCLAIMER: These are only examples, not the actual code.
if (command === 'hello') {
// message.channel.send sends a message to the message's channel.
message.channel.send("hello there")
return;
} else if (command === 'ping') {
// EMBED CONSTRUCTION: this function will show how to create an embed.
// NOTE: the client.ping property was moved to the WebSocketManager
// during the update to Discord.js V12. Use client.ws.ping instead.
// new Discord.MessageEmbed() creates an embed.
// '\n' makes a newline in the text.
// Surrounding text in **four asterisks** bolds the text.
// Math.round rounds the ping to a whole number, as the ping can be a float.
ping = Math.round(client.ws.ping)
pingEmbed = new Discord.MessageEmbed()
.setColor("#0099ff") // the default Hoppi color.
.setTitle("🏓 Pong!")
.setDescription("Ping:\n**" + ping + "**!" // Don't forget to add two asterisks to bold the text.
.setTimestamp() // sets the timestamp.
.setFooter("Powered by Hoppi") // set the footer text.
message.channel.send(pingEmbed) // Finally, send the embed in the channel.
return;
} else if (command === 'hello' && args[0] === 'hoppi') {
// The above if statement means the user has to send in a channel
// "hello hoppi", separated by a space.
// message.author.username is the author's username, so the bot's reply
// would look something like "hello, p0tato!".
message.channel.send("hello, " + message.author.username + "!")
return;
} else if (command === <your command>) {
// Your turn now! create more commands by making more if statements,
// and your bot will get even better!
}
// MORE CODE
})
client.login('SUPER_SECRET_TOKEN')Sources
Fancy developer info
Node Modules
General Node Module Usage
Specific Node Module Usage
Last updated