Skip to content

Commit

Permalink
Hug command implementation (v0.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauzy0x00 committed Mar 12, 2023
1 parent 08d1d28 commit b222c2e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
19 changes: 17 additions & 2 deletions commands/hug.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
const axios = require('axios'); // axios package to make a GET request to the Tenor API and retrieve a gif
const { SlashCommandBuilder } = require('discord.js');
const { MessageEmbed } = require('discord.js');
const { tenorAPI } = require('./config.json');

module.exports = {
data: new SlashCommandBuilder()
.setName('hug')
.setDescription('Give someone a hug :)')
.addIntegerOption(option => option.setName('hugee').setDescription('Person to hug')),
.addUserOption(option => option.setName('hugee').setDescription('Person to hug').setRequired(true)),

async execute(interaction) {
// Your code goes here
const query = 'anime-hug';
const limit = 1;
const mediaFilter = 'minimal';
const user = interaction.options.getUser('hugee');

const { data } = await axios.get(`https://api.tenor.com/v1/search?q=${query}&key=${tenorAPI}&limit=${limit}&media_filter=${mediaFilter}`);

const hugEmbed = new MessageEmbed()
.setDescription(`Sending a hug to ${hugee} ❤️`)
.setImage(data.results[0].media[0].gif.url);

await interaction.reply({ embeds: [hugEmbed] });
},
};
1 change: 1 addition & 0 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
await command.execute(interaction);
}
catch (error) {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
Expand Down
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Mauzy",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
"discord.js": "^14.7.1",
"dotenv": "^16.0.3"
},
Expand Down

0 comments on commit b222c2e

Please sign in to comment.