"Jump to Message" 按钮
"Jump to Message" Button
你好,基本上我是在做一个建议命令。一旦用户 运行 命令,它将回复 “建议已提交” 和 “跳转到建议” url 按钮但是我在使用按钮时遇到错误。这是我的代码
const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");
const db = require("quick.db")
module.exports = {
name: "suggestion",
description: "Create or reply to a suggestion",
userPermissions: "",
options: [{
name: "create",
type: 1,
description: "Create a suggestion",
options: [{
name: "suggestion",
type: 3,
required: true,
description: "The suggesiton you want to give"
}],
}, {
name: 'set-channel',
type: 1,
description: "Select the suggestion channel",
options: [{
name: "channel",
type: 7,
required: true,
description: "The channel where I should send the suggestions"
}]
}],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {
await interaction.deferReply();
const option = interaction.options.getSubcommand()
const suggestion = interaction.options.getString("suggestion")
const channel = interaction.options.getChannel("channel")
const id = interaction.options.getString("id")
const status = interaction.options.getString("status")
const response = interaction.options.getString("response")
const guildId = interaction.guild.id
let c = await db.fetch(`suggestion_${guildId}`);
if (option === "create") {
if (!c) { return interaction.editReply("<:pollno:979743680124555286> No suggestion channel were found!")
} else {
const suggestembed = new MessageEmbed()
.setTitle("New Suggestion!")
.setColor("2F3136")
.setDescription(suggestion)
.setFooter(interaction.user.username)
const url = suggestembed.url
const row = new MessageActionRow()
.addComponents(
new MessageButton() .setLabel('Jump to Message')
.setStyle('LINK')
.setURL(url)
)
const doneembed = new MessageEmbed()
.setTitle("Suggestion Submitted!")
.setDescription("Your Suggestion was submitted")
.setColor("2F3136")
interaction.editReply({ embeds: [doneembed], components: [row] })
c.send({ embeds: [suggestembed] })
}
} else if (option === "set-channel") {
if (!interaction.member.permissions.has("MANAGE_GUILD")) return interaction.editReply({ content: "<:pollno:979743680124555286> You don't have enough power to execute this command", ephemeral: true })
if (channel.type !== "GUILD_TEXT") return interaction.editReply({ content: "<:pollno:979743680124555286> Invalid Channel Type!", ephemeral: true })
await db.set(`suggestion_${guildId}`, channel.id);
const last = new MessageEmbed()
.setTitle("Suggestion Setup!")
.setDescription("Suggestion channel have been setup")
.setColor("2F3136")
interaction.editReply({ embeds: [last] })
}
}
}
The Error
Error: MessageButton must be a String
希望得到一些帮助,因为这已经成为我停止开发的问题!谢谢
您当前正在使用 MessageEmbed().url
作为消息 url 的变量,但它返回未定义。
你必须先 post 消息,然后才能接听他的 URL。
这是一个例子:
const suggestembed = new MessageEmbed()
.setTitle("New Suggestion!")
.setColor("2F3136")
.setDescription(suggestion)
.setFooter(interaction.user.username)
const msg = await interaction.channel.send({embeds:[suggestembed]})
const url = msg.url
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('Jump to Message')
.setStyle('LINK')
.setURL(url)
)
你好,基本上我是在做一个建议命令。一旦用户 运行 命令,它将回复 “建议已提交” 和 “跳转到建议” url 按钮但是我在使用按钮时遇到错误。这是我的代码
const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");
const db = require("quick.db")
module.exports = {
name: "suggestion",
description: "Create or reply to a suggestion",
userPermissions: "",
options: [{
name: "create",
type: 1,
description: "Create a suggestion",
options: [{
name: "suggestion",
type: 3,
required: true,
description: "The suggesiton you want to give"
}],
}, {
name: 'set-channel',
type: 1,
description: "Select the suggestion channel",
options: [{
name: "channel",
type: 7,
required: true,
description: "The channel where I should send the suggestions"
}]
}],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {
await interaction.deferReply();
const option = interaction.options.getSubcommand()
const suggestion = interaction.options.getString("suggestion")
const channel = interaction.options.getChannel("channel")
const id = interaction.options.getString("id")
const status = interaction.options.getString("status")
const response = interaction.options.getString("response")
const guildId = interaction.guild.id
let c = await db.fetch(`suggestion_${guildId}`);
if (option === "create") {
if (!c) { return interaction.editReply("<:pollno:979743680124555286> No suggestion channel were found!")
} else {
const suggestembed = new MessageEmbed()
.setTitle("New Suggestion!")
.setColor("2F3136")
.setDescription(suggestion)
.setFooter(interaction.user.username)
const url = suggestembed.url
const row = new MessageActionRow()
.addComponents(
new MessageButton() .setLabel('Jump to Message')
.setStyle('LINK')
.setURL(url)
)
const doneembed = new MessageEmbed()
.setTitle("Suggestion Submitted!")
.setDescription("Your Suggestion was submitted")
.setColor("2F3136")
interaction.editReply({ embeds: [doneembed], components: [row] })
c.send({ embeds: [suggestembed] })
}
} else if (option === "set-channel") {
if (!interaction.member.permissions.has("MANAGE_GUILD")) return interaction.editReply({ content: "<:pollno:979743680124555286> You don't have enough power to execute this command", ephemeral: true })
if (channel.type !== "GUILD_TEXT") return interaction.editReply({ content: "<:pollno:979743680124555286> Invalid Channel Type!", ephemeral: true })
await db.set(`suggestion_${guildId}`, channel.id);
const last = new MessageEmbed()
.setTitle("Suggestion Setup!")
.setDescription("Suggestion channel have been setup")
.setColor("2F3136")
interaction.editReply({ embeds: [last] })
}
}
}
The Error
Error: MessageButton must be a String
希望得到一些帮助,因为这已经成为我停止开发的问题!谢谢
您当前正在使用 MessageEmbed().url
作为消息 url 的变量,但它返回未定义。
你必须先 post 消息,然后才能接听他的 URL。 这是一个例子:
const suggestembed = new MessageEmbed()
.setTitle("New Suggestion!")
.setColor("2F3136")
.setDescription(suggestion)
.setFooter(interaction.user.username)
const msg = await interaction.channel.send({embeds:[suggestembed]})
const url = msg.url
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('Jump to Message')
.setStyle('LINK')
.setURL(url)
)