Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avatar): avatar command guildonly property #1

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions commands/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { MessageEmbed } = require('discord.js')

module.exports = {
name: 'avatar',
description: 'Shows your avatar url',
aliases: ['av'],
args: false,
guildOnly: true,
execute: function (message, args) {
const user = message.author
const name = !user.displayName ? user.username : user.displayName

const avatarEmbed = new MessageEmbed()
.setURL(user.displayAvatarURL())
.setTitle(name)
.setThumbnail(user.displayAvatarURL({ dynamic: true, size: 128 }))

if (message.guild.available) {
avatarEmbed
.addField('Roles',
message.guild.member(user).roles.cache
.mapValues(role => role.name)
.reduce((acc, role) => acc + '\n' + role)
)
}

message.reply(avatarEmbed)
}
}
30 changes: 18 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require('http')
const fs = require('fs')
const Discord = require('discord.js')
const { prefix, token } = require('./config.js')
const { prefix, token, listenServer } = require('./config.js')
const { salutations } = require('./commands/phrases.json')

const client = new Discord.Client()
Expand All @@ -28,9 +28,9 @@ client.on('message', message => {
const commandName = args.shift().toLowerCase()

const command = client.commands.get(commandName) ||
client.commands.find(cmd => {
return cmd.aliases && cmd.aliases.includes(commandName)
})
client.commands.find(cmd => {
return cmd.aliases && cmd.aliases.includes(commandName)
})

if (!command) return

Expand Down Expand Up @@ -63,6 +63,10 @@ client.on('message', message => {
timestamps.set(message.author.id, now)
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount)

if (command.guildOnly && message.channel.type === 'dm') {
return message.reply('I can\'t execute that command inside DMs!')
}

try {
command.execute(message, args)
} catch (error) {
Expand All @@ -75,7 +79,7 @@ client.login(token)
.catch((error) => {
if (error.code === 'TOKEN_INVALID') {
console.error('Discord token is not acceptable. Please set config.json or DISCORD_TOKEN appropiately.')
} else {
} else {
throw error
}
})
Expand All @@ -84,10 +88,12 @@ function randomFrom (anArray) {
return anArray[Math.floor(Math.random() * anArray.length)]
}

http.createServer(
function (request, response) {
const content = randomFrom(salutations)
response.writeHead(200)
response.end(content, 'utf-8')
}
).listen(process.env.PORT || 443)
if (listenServer) {
http.createServer(
function (request, response) {
const content = randomFrom(salutations)
response.writeHead(200)
response.end(content, 'utf-8')
}
).listen(process.env.PORT || 443)
}
Loading