在此search
命令中,for in
循环不会将字段添加到嵌入中。当我使用该命令时,我会获得在创建嵌入时定义的名称和描述。但我没有得到我在for in
循环中添加的字段。
这是返回的图像,以防万一它有助于回答我的问题:
我的search
命令代码:
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'search',
description: 'Searches for a song and returns the results.',
options: [
{
name: 'search_term',
description: 'The song to search for.',
type: 'STRING',
required: true
},
{
name: 'limit',
type: 'INTEGER',
description: 'Number of results to return.',
required: true
},
{
name: 'type',
type: 'STRING',
description: 'The type of search result.',
required: true,
choices: [{
name: 'Video',
value: 'video'
},
{
name: 'Playlist',
value: 'playlist'
}]
}
],
async execute(interaction) {
const query = await interaction.options.getString('search_term')
const limit = await interaction.options.getInteger('limit')
const type = await interaction.options.getString('type')
let type2 = 'x'
if (type === 'video') type2 = 'Video'
else if (type === 'playlist') type2 = 'Playlist'
let results = await interaction.client.distube.search(query, { limit: limit, type: type })
let embed = new MessageEmbed()
.setTitle('search')
.setDescription('Searches for a song and returns the results.')
for (const result in results) {
if (result.type === 'video') {
embed.addFields({
name :result.name,
value: `ID: ${result.id}\nType: ${type2}\nURL: ${result.url}\nViews: ${result.views}\nDuration: ${result.formattedDuration}\nLive: ${result.isLive}`,
inline: true})
}
else if (result.type === 'playlist') {
embed.addFields({
name: result.name,
value: `ID: ${result.id}\nType: ${type2}\nURL: ${result.url}\nViews: ${result.views}`,
inline: true})
}
}
await interaction.reply({embeds: [embed]})
},
};