From 5f7769d2b0df23c5d4646c13acb205f0bb1e4bd1 Mon Sep 17 00:00:00 2001 From: Carlos Lima Date: Sun, 18 Apr 2021 18:51:04 -0300 Subject: [PATCH] Add error handler to examples (#1181) --- README.md | 4 ++++ examples/basicCommands.js | 4 ++++ examples/embed.js | 4 ++++ examples/intent.js | 4 ++++ examples/pingpong.js | 4 ++++ examples/playFile.js | 4 ++++ examples/reactionButtons.js | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 73fcba56b..e5d8e0c55 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.on("messageCreate", (msg) => { // When a message is created if(msg.content === "!ping") { // If the message content is "!ping" bot.createMessage(msg.channel.id, "Pong!"); diff --git a/examples/basicCommands.js b/examples/basicCommands.js index 9a9cfec11..2fc89f5b3 100644 --- a/examples/basicCommands.js +++ b/examples/basicCommands.js @@ -11,6 +11,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.registerCommandAlias("halp", "help"); // Alias !halp to !help bot.registerCommand("ping", "Pong!", { // Make a ping command diff --git a/examples/embed.js b/examples/embed.js index 3013b1397..eaa12658e 100644 --- a/examples/embed.js +++ b/examples/embed.js @@ -7,6 +7,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.on("messageCreate", (msg) => { // When a message is created if(msg.content === "!embed") { // If the message content is "!embed" bot.createMessage(msg.channel.id, { diff --git a/examples/intent.js b/examples/intent.js index 119b266a3..3339bf266 100644 --- a/examples/intent.js +++ b/examples/intent.js @@ -12,6 +12,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.on("guildCreate", (guild) => { // When the client joins a new guild console.log(`New guild: ${guild.name}`); }); diff --git a/examples/pingpong.js b/examples/pingpong.js index 5c29d8667..0cacf9e9b 100644 --- a/examples/pingpong.js +++ b/examples/pingpong.js @@ -7,6 +7,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.on("messageCreate", (msg) => { // When a message is created if(msg.content === "!ping") { // If the message content is "!ping" bot.createMessage(msg.channel.id, "Pong!"); diff --git a/examples/playFile.js b/examples/playFile.js index 4d429ef12..6c58173d9 100644 --- a/examples/playFile.js +++ b/examples/playFile.js @@ -9,6 +9,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.on("messageCreate", (msg) => { // When a message is created if(msg.content.startsWith(playCommand)) { // If the message content starts with "!play " if(msg.content.length <= playCommand.length + 1) { // Check if a filename was specified diff --git a/examples/reactionButtons.js b/examples/reactionButtons.js index e317c0d54..a3e3f841e 100644 --- a/examples/reactionButtons.js +++ b/examples/reactionButtons.js @@ -11,6 +11,10 @@ bot.on("ready", () => { // When the bot is ready console.log("Ready!"); // Log "Ready!" }); +bot.on("error", (err) => { + console.error(err); // or your preferred logger +}); + bot.registerCommand("ping", "Pong!", { // Make a ping command // Responds with "Pong!" when someone says "!ping" description: "Pong!",