最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

data.embeds[0][LIST

网站源码admin39浏览0评论

data.embeds[0][LIST

data.embeds[0][LIST

调用返回要显示的嵌入的斜杠命令时出现此错误:

import { EmbedBuilder } from "discord.js"
import fetch from "node-fetch"



export const traitDescription = async (trait) => {
    const api_url = '/api/traits'
    let result = await fetch(api_url)
    try { result = await result.json(); } catch (err) { result = null }
    var traitDes = false
    if (trait.toLowerCase() === 'traits') {
        return 0
    }


    result.forEach((item) => {
        if (trait.toLowerCase() === item.name.toLowerCase()) {
            traitDes = item
        }
    })

    if (traitDes != false) {
        const traitEmbed = new EmbedBuilder()
                .setTitle(traitDes.name)
                .setDescription(traitDes.effect)
                .setURL(traitDes.wikiUrl)
    } else {
        return 0
    }

    return traitEmbed
}

export default traitDescription

此函数正在 api 中搜索通过斜杠命令输入的特征名称,如果没有该名称的特征,则返回包含数据的嵌入或整数 0。

在我的 index.js 文件中,我在“interactionCreate”函数中调用这样的斜杠命令(我还有其他可用的命令):

else if (commandName === 'trait') {
        let traitName = options.getString('traitname')
        const traitEmbed = traitDescription(traitName)
        if (traitEmbed === 0) {
            interaction.reply({
                content: 'This is not a trait <:bruhvel:1100574618110132255>',
                ephemeral: true,
            })
        } else {
            const messageId = interaction.reply({ embeds: [ traitEmbed ] })

        }
    }
回答如下:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论