2
votes

I've made a couple discord bots but I'm still very much a novice and I was wondering how I would be able to make a bot that embeds any website (kind of like how YouTube has its video embeds but with text and multimodal elements of a website in one embed) that is posted after the bot's prefix & the command 'site'. I don't know how to make a bot respond to stimulus, and I am not sure how the embed would work. I just want to be able to make it so that any user can type into discord =site *Enter URL here* and it would create an embed of the site so people won't skim over links. Here is my code so far, its pretty basic but I have no clue how to implement the ability to embed websites. I know that the site command does not work in the slightest, but these were my attempts:

const Discord = require('discord.js');

const client = new Discord.Client();

const prefix = '=';

client.once('ready', () => {
    console.log('WebPress is now online!');
    client.user.setActivity('Microsoft Word 1996', { type: 'PLAYING' })
});


client.on('message', message => {
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/)
    const command = args.shift().toLowerCase();


    if (command === 'ping'){
        message.channel.send('`Pong!`');
    } else if (command == 'site'){
        const siteEmbed = new Discord.MessageEmbed()
            .setURL(**THE URL THAT A USER SENDS**)
            if (!message.channel.first.size()) {
                return message.reply("please give me a website URL to embed!");
        } else message.channel.first();
            message.channel.send(`${siteEmbed}`);
    }

});

client.login('My token here');

Thanks for any help you have and enjoy your day! :)

2

2 Answers

1
votes

To send an embed with a link you can do this. This will create an embed with a hyperlink in the title.

const siteEmbed = new Discord.MessageEmbed()
    .setURL(args[0])
    .setTitle("Your desription here");

See here for more information on embeds https://discordjs.guide/popular-topics/embeds.html#embed-preview

To check if your user actually sends a link you can check if the first argument exists.

if (!args[0]) {
    return message.reply("please give me a website URL to embed!");
}
0
votes

For anyone that is looking at this, this problem was long-resolved using Pupeteer API to take a screenshot of a website and attach the URL that the user sent. Thanks for the help back then when I forgot args existed lol :D