简体   繁体   中英

Discord.js Button Links

Hello I am trying to use a discord.js button to link to a website

This is what I attempted to do

const row = new MessageActionRow()
.addComponents(
new MessageButton()
    .setCustomId('whatever')
    .setLabel('CLICK THIS')
    .setLink("google.com")
    .setStyle('LINK'),
);

However this does not work due to set link not being a function

And the documentation doesnt help me out with this

Conor Reid is right

const row = new MessageActionRow()
.addComponents(
new MessageButton()
    .setLabel('CLICK THIS')
    .setURL("urlhere")
    .setStyle('LINK'),
);

The correct function is setUrl()

MessageButton.setLink() is not a function. Although I can see why this may be confusing because of the setStyle('LINK') being required. The correct function is .setURL(url) . The MessageButton documentation is available here https://discord.js.org/#/docs/main/stable/class/MessageButton

You need to use setURL instead of setLink

It is in the docs

let url 'https://google.com'
const row = new MessageActionRow()
.addComponents(
new MessageButton()
    .setLabel('Google')
    .setURL(url)
    .setStyle('LINK')
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM