Skip to content

Instantly share code, notes, and snippets.

@acrylic-style
Created May 11, 2020 08:00
Show Gist options
  • Save acrylic-style/fc39f8f0ccd9f1b7801b9c8e306d8edd to your computer and use it in GitHub Desktop.
Save acrylic-style/fc39f8f0ccd9f1b7801b9c8e306d8edd to your computer and use it in GitHub Desktop.
msg.js
const Discord = require('discord.js')
const { Command } = require('bot-framework')
module.exports = class extends Command {
constructor() {
const opts = {
args: ['<Message URL>'],
}
super('msg', opts)
}
async run(msg, lang, args) {
if (!args[1]) return
args = args.splice(1)
args.forEach(async arg => {
if (!/discordapp\.com\/channels\/(.*)\/(.*)\/(.*)$/.test(arg)) return
const regex = /discordapp\.com\/channels\/(.*)\/(.*)\/(.*)$/.exec(arg)
const sguild = regex[1]
const schannel = regex[2]
const message = regex[3]
let channel
let guild
if (sguild === '@me') {
const user = await msg.client.channels.fetch(schannel).catch(e => {
console.error(e)
return null
})
if (!user) return
channel = user
guild = { name: `DM: ${user.recipient.tag} (${user.recipient.id})`, avatar: user.recipient.avatarURL() }
} else {
channel = await msg.client.channels.fetch(schannel).catch(e => {
console.error(e)
return null
})
if (!channel) return
if (channel.constructor.name !== 'TextChannel') return
guild = { name: `#${channel.name} - ${channel.guild.name}`, avatar: channel.guild.iconURL() }
}
const fetched = await channel.messages.fetch(message).catch(e => {
console.error(e)
return null
})
if (!fetched) return
const embed = new Discord.MessageEmbed()
.setURL(`https://discordapp.com/channels/${sguild}/${schannel}/${message}`)
.setAuthor(fetched.author.tag, fetched.author.avatarURL())
.setDescription(fetched.content)
.setTimestamp(fetched.createdTimestamp)
.setFooter(`${guild.name}`, guild.avatar)
if (fetched.attachments && fetched.attachments.size != 0) embed.setImage(fetched.attachments.first().url)
msg.channel.send(embed)
if (fetched.embeds) fetched.embeds.forEach((embed, i) => {
msg.channel.send(`Embed ${i+1}:`, { embed })
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment