Skip to content
Advertisement

“Jump to Message” Button

Hi so basically I’m making a suggestion command. Once the user ran the command it will reply “Suggestion Submitted” with “Jump to Suggestion” url button but I’m getting error with the button. Here’s my code

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

Hope to get the some help with this as this have become the issue for me that make my development stopped! Thanks

Advertisement

Answer

You’re currently using MessageEmbed().url as a variable for the message url, but it returned undefined.

You have to post the message before picking up his URL. Here’s an example :

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)
)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement