如何在Discord.js中发送带可点击多链接的Embed消息?
Fixing Clickable Links in Your Discord Music Bot's Embed
Hey there! The problem you're hitting is that you're just tacking the URL onto your title as plain text—Discord won't recognize that as a clickable link. To fix this, you need to use Discord's supported Markdown link syntax in your embed description.
Here's the adjusted code with explanations:
Modified Code Snippet
if (command === 'test') { var search = message.content.split(/\s+/g).slice(1).join(" "); if (!search.length) { return message.channel.send("PLs enter a name!"); } else { const puppeteer = require("puppeteer"); const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(`https://i hide website cause privacy?keyword=${search}`); let Anime = await page.evaluate(() => { let items = document.querySelectorAll('ul[class= "last-film-box"] > li > a'); let links = []; items.forEach(item => { links.push({ titl: item.title, url: item.href }); }); return links; }); let i = 0; // 👇 This is the critical fix: use Markdown link syntax let content = Anime.map(e => { i++; return `${i}/ [${e.titl.slice(0, 50)}](${e.url})`; }) let ContentEmbed = new Discord.MessageEmbed(); ContentEmbed.setTitle("Here the result"); ContentEmbed.setDescription(content.join('\n')); // 👈 Join results with newlines for readability message.channel.send(ContentEmbed); // Clean up: close the Puppeteer browser to avoid resource leaks await browser.close(); } }
Key Changes Breakdown:
- Markdown Link Format: Instead of concatenating title and URL as plain text, we use
[display text](link URL)syntax. Discord'sMessageEmbedautomatically parses this into a clickable link. - Newline Separation: Adding
.join('\n')when setting the description ensures each result appears on its own line, making the embed far easier to scan. - Browser Cleanup: A small but important addition—closing the Puppeteer browser after use prevents unnecessary resource usage.
Quick side note: You have a typo in titl (should be title), but that's a minor consistency fix if you want to adjust it later.
内容的提问来源于stack exchange,提问作者Thiện
相关产品推荐
相关产品推荐

