You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Discord.js中发送带可点击多链接的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's MessageEmbed automatically 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:12:47