Ссылка / руководство, которое я использую: https://www.npmjs.com/package /discord.js-menu
Мой код:
/* Import all the usual stuff. This shouldn't be anything new. */
const { Client, MessageEmbed } = require('discord.js')
const { Menu } = require('discord.js-menu')
const client = new Client()
/* Run this code every time a new message is sent. */
client.on('message', message => {
if (message.content === "!help") {
/*
* The menu class takes 4 parameters.
* 1) A channel to send the menu to
* 2) A user ID to give control over the navigation,
* 3) An array of Page objects, each being a unique page of the menu
* 4) How long, in milliseconds, you want the menu to wait for new reactions
*/
let helpMenu = new Menu(message.channel, message.author.id, [
{
/*
* A page object consists of three items:
* 1) A name. This is used as a unique destination name for reactions.
* 2) Some content. This is a rich embed.
* You can use {object: formatting} or .functionFormatting() for embeds. Whichever you prefer.
* 3) A set of reactions, linked to either a page destination or a function.* (See example pages)
*
* Reactions can be emojis or custom emote IDs, and reaction destinations can be either the names
* of pages, () => { functions }, or special destination names. See below for a list of these.
*/
/* You can call pages whatever you like. The first in the array is always loaded first. */
name: 'p1',
content: new MessageEmbed({
title: 'Page 1',
description: 'This is some helpful info!',
fields: [
{ name: "this is page 1", value: "p1" }
]
}),
reactions: {
'❌': 'p1',
'➡': 'p2'
}
},
{
/*
* A page object consists of three items:
* 1) A name. This is used as a unique destination name for reactions.
* 2) Some content. This is a rich embed.
* You can use {object: formatting} or .functionFormatting() for embeds. Whichever you prefer.
* 3) A set of reactions, linked to either a page destination or a function.* (See example pages)
*
* Reactions can be emojis or custom emote IDs, and reaction destinations can be either the names
* of pages, () => { functions }, or special destination names. See below for a list of these.
*/
/* You can call pages whatever you like. The first in the array is always loaded first. */
name: 'p2',
content: new MessageEmbed({
title: 'Page 2',
description: 'This is some helpful info!',
fields: [
{ name: "this is page 2", value: "p2" }
]
}),
reactions: {
'⬅': 'p1',
'➡': 'p3'
}
},
{
/*
* A page object consists of three items:
* 1) A name. This is used as a unique destination name for reactions.
* 2) Some content. This is a rich embed.
* You can use {object: formatting} or .functionFormatting() for embeds. Whichever you prefer.
* 3) A set of reactions, linked to either a page destination or a function.* (See example pages)
*
* Reactions can be emojis or custom emote IDs, and reaction destinations can be either the names
* of pages, () => { functions }, or special destination names. See below for a list of these.
*/
/* You can call pages whatever you like. The first in the array is always loaded first. */
name: 'p3',
content: new MessageEmbed({
title: 'Page 3',
description: 'This is some helpful info!',
fields: [
{ name: "this is page 3", value: "p3" }
]
}),
reactions: {
'⬅': 'p2',
'❌': 'p3'
}
},
], 60000)
/* Run Menu.start() when you're ready to send the menu in chat.
* Once sent, the menu will automatically handle everything else.
*/
helpMenu.start()
}
})
client.login("Get your bot's oauth token at https://discord.com/developers/applications")
Я делаю что-то вроде страницы, и я хочу, чтобы каждый мог управлять страницами, а не просто message.author.id
. Есть ли способ сделать это?
Дело в том, что я пытался удалить message.author.id
и заменить message.author.id
на null
.
2 ответа
Похоже, вы можете добавить только одного пользователя. Если вы проверите исходный код, то увидите что constructor
' Второй аргумент (идентификатор пользователя) используется для получения одного пользователя следующим образом: client.users.cache.get(this.userID)
.
Он также проверяет, является ли пользователь, который отреагировал, переданным пользователем (message.author.id
в вашем случае). Если нет, снимает реакцию:
reactionCollector.on('collect', (reaction, user) => {
if (user.id !== this.userID || !Object.keys(this.currentPage.reactions).includes(reactionName)) {
return reaction.users.remove(user)
}
// ...
}
Вы не можете просто избавиться от этого аргумента, и вы, конечно, не можете заменить его на guild.id
, как предлагал другой ответ.
Итак, ответ таков: без разветвления проекта и внесения изменений вы не можете разрешить всем контролировать страницу.
Попробуйте message.guild.id
вместо message.author.id
.
Похожие вопросы
Новые вопросы
javascript
По вопросам программирования на ECMAScript (JavaScript / JS) и его различных диалектах / реализациях (кроме ActionScript). Включите все соответствующие теги в свой вопрос; например, [node.js], [jquery], [json] и т. д.