From 8451741ec43b70c7cc5eacae56f21a21b108055d Mon Sep 17 00:00:00 2001 From: Lohith Ravuru Date: Mon, 14 Dec 2020 22:24:57 +0530 Subject: [PATCH 1/2] message embed to main.js --- main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index ab10d58..9c29bd1 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,7 @@ const Canvas = require('canvas'); const client = new Discord.Client(); const console = require("./theme.js"); const { prefix, token } = require('./configs/config.json'); - +const messageEmbed= new Discord.MessageEmbed(); client.commands = new Discord.Collection(); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); @@ -109,7 +109,9 @@ client.on('message', message => { client.commands.get(command).execute(message, args); } catch (error) { console.error(error); - message.reply('there was an error trying to execute that command!'); + messageEmbed.setTitle("there was an error trying to execute that command!") + .setColor('RED'); + message.reply(messageEmbed); } }); From e9acd3a46270b191c93f24e588fd49c911d81b6e Mon Sep 17 00:00:00 2001 From: chidaksh Date: Tue, 15 Dec 2020 21:38:13 +0530 Subject: [PATCH 2/2] conveted all responses to embeds --- commands/user-info.js | 16 +++++++++++----- commands/verify.js | 27 ++++++++++++++++++--------- commands/welcome-test.js | 4 +++- main.js | 4 +++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/commands/user-info.js b/commands/user-info.js index 09eb537..f96124c 100644 --- a/commands/user-info.js +++ b/commands/user-info.js @@ -4,7 +4,8 @@ const { spreadsheetId, sheetName, } = require('../services/googleSheetsService.js'); - +const Discord = require('discord.js'); +const messageEmbed= new Discord.MessageEmbed(); // Id of the spreadsheet file (it is in the url of the google sheet) const logThemes = require("../theme.js"); @@ -58,15 +59,18 @@ async function getDetails(message) { } else if (house === 'D') { house = 'Darco'; } - - message.channel.send(`Your Name is ${realName}\nYour Roll No is ${rollNumber}\nYour house is ${house}`); + messageEmbed.setTitle(`Your Name is ${realName}\nYour Roll No is ${rollNumber}\nYour house is ${house}`) + .setColor('ORANGE'); + message.channel.send(messageEmbed); // TODO Do not print the roll number // TODO Assign a role based on the roll number like give `role-a` if rollNumber starts with 1901 return; } }; - message.reply("Sorry we couldn't find you in our database. \ + messageEmbed.setTitle("Sorry we couldn't find you in our database. \ Please ping"+ "<@&" + modRole.id + "> to identify you.") + .setColor('RED'); + message.reply(messageEmbed); return; } @@ -80,7 +84,9 @@ module.exports = { // If someone runs !user-info @dhushyanth in the message // then identify the mentioned user and fetch the // roll number of that user - message.channel.send(`Your username: ${userName}\n`); + messageEmbed.setTitle(`Your username: ${userName}\n`) + .setColor('GREEN'); + message.channel.send(messageEmbed); getDetails(message); // var role = message.guild.roles.find(role => role.name === "role-b"); // message.member.addRole(role); diff --git a/commands/verify.js b/commands/verify.js index 0b5b69f..67a8350 100644 --- a/commands/verify.js +++ b/commands/verify.js @@ -4,17 +4,18 @@ const { spreadsheetId, sheetName, } = require('../services/googleSheetsService.js'); - - - +const Discord = require('discord.js'); +const messageEmbed= new Discord.MessageEmbed(); async function assignRole(branch, gradYear, message) { let { cache } = message.guild.roles; let modRole = cache.find(role => role.name === "moderator"); let yearRole = cache.find(role => role.name.includes(gradYear)); if (!yearRole) { - message.reply("Year role could not be assigned. \ + messageEmbed.setTitle("Year role could not be assigned. \ Please ping"+ "<@&" + modRole.id + "> to identify you.") + .setColor('RED'); + message.reply(messageEmbed); } else { await message.member.roles.add(yearRole); @@ -23,8 +24,10 @@ async function assignRole(branch, gradYear, message) { let branchRole = cache.find(role => role.name.includes(branch)); if (!branchRole) { - message.reply("Branch role could not be assigned. \ + messageEmbed.setTitle("Branch role could not be assigned. \ Please ping"+ "<@&" + modRole.id + "> to identify you.") + .setColor('RED'); + message.reply(messageEmbed); } else { await message.member.roles.add(branchRole); @@ -77,8 +80,10 @@ async function getDetails(message, username) { if (message.author.id === message.guild.ownerID) return message.reply('I can\'t change your nickname.'); await message.member.setNickname(`${username}-${part[0]} ${lastName}`); - messageString += "Nickname Changed\n" - message.reply(messageString) + messageString += "Nickname Changed\n"; + messageEmbed.setTitle(messageString) + .setColor('GOLD'); + message.reply(messageEmbed); } catch (err) { console.error(err); } @@ -86,7 +91,9 @@ async function getDetails(message, username) { return; } } - message.reply("User not found"); + messageEmbed.setTitle("User not found") + .setColor('RED'); + message.reply(messageEmbed); return; } @@ -100,7 +107,9 @@ module.exports = { getDetails(message, username); } else { - message.reply("The command you are looking for is-!verify me"); + messageEmbed.setTitle("The command you are looking for is-!verify me") + .setColor('YELLOW'); + message.reply(messageEmbed); } } } diff --git a/commands/welcome-test.js b/commands/welcome-test.js index 5089600..7320199 100644 --- a/commands/welcome-test.js +++ b/commands/welcome-test.js @@ -1,5 +1,6 @@ const Canvas = require('canvas'); const Discord = require('discord.js'); +const messageEmbed= new Discord.MessageEmbed(); // Pass the entire Canvas object because you'll need to access its width, as well its context const applyText = (canvas, text) => { @@ -61,6 +62,7 @@ module.exports = { ctx.drawImage(avatar, (0.5 + (canvas.width / 2 - 100)) | 0, (0.5 + 50) | 0, 200, 200); const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png'); - message.channel.send(attachment); + messageEmbed.attachFiles([attachment]); + message.channel.send(messageEmbed); }, }; \ No newline at end of file diff --git a/main.js b/main.js index 9c29bd1..5a711fe 100644 --- a/main.js +++ b/main.js @@ -98,7 +98,9 @@ client.on('message', message => { const command = args.shift().toLowerCase(); if (message.channel.type === 'dm' || message.channel.name !== 'testing') { - message.reply('Hello there'); + messageEmbed.setTitle("Hello there") + .setColor('AQUA'); + message.reply(messageEmbed); return; }