I 100% stole this idea from NQN... The snippet will delete any Discord message links and replace them with what the message says so that you don't have to click on the link to read the message. There is no setup, just install it to your bot and send some message links!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//Checks if the message is a link
if (context.params.event.content.startsWith(`https://discord.com/channels/`)) {
//Takes the link and separates the ids from the link
let id = context.params.event.content;
id = id.replace(/\D/g, '');
id = id.toString().match(/\d{1,18}/g);
let message_id = id[2];
let channel = id[1];
let guild = id[0];
//Deletes the link message
await lib.discord.channels['@0.3.0'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
//Retrieves the message that is being referneced
let message = await lib.discord.channels['@0.3.0'].messages.retrieve({
message_id: `${message_id}`,
channel_id: `${channel}`,
});
//Retrieves the user/author for the webhook
let user = await lib.discord.guilds['@0.2.2'].members.retrieve({
user_id: context.params.event.author.id,
guild_id: context.params.event.guild_id,
});
//Creates the webhook
let webhook = await lib.discord.webhooks['@0.0.0'].create({
channel_id: context.params.event.channel_id,
name: `New Webhook`,
});
//If the user/author has a nickname it will use the nickname
if (!user.nick) {
webhookName = user.user.username;
} else {
webhookName = user.nick;
}
//Gets the avatar for the webhook
let avatar = user.user.avatar_url;
//Checks if the avatar is animated
if (avatar) {
let gifCheckResponse = await lib.http.request['@1.1.5']({
method: 'GET',
url: avatar.replace('.png', '.gif'),
});
if (gifCheckResponse.statusCode === 200) {
avatar = avatar.replace('.png', '.gif');
}
} else if (!avatar) {
avatar = `https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png`
}
//Gets the avatar of the linked message's author
let pfp = `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png?size=1024`;
//Gets the original link again
let link = context.params.event.content;
//Checks if the message has an attachemnt
if (message.attachments[0]) {
//Sends a message via the webhook
await lib.discord.webhooks['@0.1.0'].execute({
webhook_id: webhook.id,
webhook_token: webhook.token,
embeds: [
{
author: {name: message.author.username, icon_url: pfp},
description: message.content,
color: 0xffffff,
fields: [
{
name: `**Jump**`,
value: `[Go to message!](${link})`,
},
],
image: {url: message.attachments[0].url},
},
],
username: webhookName,
avatar_url: avatar,
});
//If there is no attachment it sends just the message via the webhook
} else {
await lib.discord.webhooks['@0.1.0'].execute({
webhook_id: webhook.id,
webhook_token: webhook.token,
embeds: [
{
author: {name: message.author.username, icon_url: pfp},
description: message.content,
color: 0xffffff,
fields: [
{
name: `**Jump**`,
value: `[Go to message!](${link})`,
},
],
},
],
username: webhookName,
avatar_url: avatar,
});
}
//Deletes the webhook
await lib.discord.webhooks['@0.0.0'].destroy({
webhook_id: `${webhook.id}`,
});
}