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
JavaScript
x
102
102
1
const { MessageActionRow, MessageButton, MessageEmbed, MessageSelectMenu } = require("discord.js");
2
3
const db = require("quick.db")
4
5
6
module.exports = {
7
name: "suggestion",
8
description: "Create or reply to a suggestion",
9
userPermissions: "",
10
options: [{
11
name: "create",
12
type: 1,
13
description: "Create a suggestion",
14
options: [{
15
name: "suggestion",
16
type: 3,
17
required: true,
18
description: "The suggesiton you want to give"
19
}],
20
}, {
21
name: 'set-channel',
22
type: 1,
23
description: "Select the suggestion channel",
24
options: [{
25
name: "channel",
26
type: 7,
27
required: true,
28
description: "The channel where I should send the suggestions"
29
}]
30
}],
31
32
33
/**
34
*
35
* @param {Client} client
36
* @param {CommandInteraction} interaction
37
* @param {String[]} args
38
*/
39
40
run: async (client, interaction, args) => {
41
await interaction.deferReply();
42
43
const option = interaction.options.getSubcommand()
44
45
const suggestion = interaction.options.getString("suggestion")
46
47
const channel = interaction.options.getChannel("channel")
48
49
const id = interaction.options.getString("id")
50
51
const status = interaction.options.getString("status")
52
53
const response = interaction.options.getString("response")
54
55
const guildId = interaction.guild.id
56
57
let c = await db.fetch(`suggestion_${guildId}`);
58
59
if (option === "create") {
60
if (!c) { return interaction.editReply("<:pollno:979743680124555286> No suggestion channel were found!")
61
} else {
62
63
const suggestembed = new MessageEmbed()
64
.setTitle("New Suggestion!")
65
.setColor("2F3136")
66
.setDescription(suggestion)
67
.setFooter(interaction.user.username)
68
69
const url = suggestembed.url
70
71
const row = new MessageActionRow()
72
.addComponents(
73
new MessageButton() .setLabel('Jump to Message')
74
.setStyle('LINK')
75
.setURL(url)
76
)
77
const doneembed = new MessageEmbed()
78
.setTitle("Suggestion Submitted!")
79
.setDescription("Your Suggestion was submitted")
80
.setColor("2F3136")
81
82
interaction.editReply({ embeds: [doneembed], components: [row] })
83
84
c.send({ embeds: [suggestembed] })
85
}
86
} else if (option === "set-channel") {
87
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 })
88
89
90
if (channel.type !== "GUILD_TEXT") return interaction.editReply({ content: "<:pollno:979743680124555286> Invalid Channel Type!", ephemeral: true })
91
92
await db.set(`suggestion_${guildId}`, channel.id);
93
const last = new MessageEmbed()
94
.setTitle("Suggestion Setup!")
95
.setDescription("Suggestion channel have been setup")
96
.setColor("2F3136")
97
98
interaction.editReply({ embeds: [last] })
99
}
100
}
101
}
102
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 :
JavaScript
1
17
17
1
const suggestembed = new MessageEmbed()
2
.setTitle("New Suggestion!")
3
.setColor("2F3136")
4
.setDescription(suggestion)
5
.setFooter(interaction.user.username)
6
7
const msg = await interaction.channel.send({embeds:[suggestembed]})
8
const url = msg.url
9
10
const row = new MessageActionRow()
11
.addComponents(
12
new MessageButton()
13
.setLabel('Jump to Message')
14
.setStyle('LINK')
15
.setURL(url)
16
)
17