[英]Making a discord.js reaction help menu
So, im making a reation based help-menu for my discord bot.所以,我为我的 discord 机器人制作了一个基于反应的帮助菜单。 Here's my current code:
这是我当前的代码:
module.exports = {
name: 'helpall',
description: 'help embed menu',
async execute(message, args, Discord, client) {
const embed1 = new Discord.MessageEmbed()
.setTitle('Moderation commands')
.setDescription('Please enter . before every command to use it')
.addFields(
{name: '`.kick <@user>`', value: '`kicks a member from the server`'},
{name: '`.ban <@user>`', value: '`bans a member from the server`'},
{name: '`.prune <amount>`', value: '`deletes a certain amount of messages in the channel`'},
{name: '`.lock`', value: '`locks the channel the message was sent in`'},
{name: '`.unlock`', value: '`unlocks a previously locked channel`'},
{name: '`.mute <@user>`', value: '`mutes a member`'},
{name: '`.unmute <@user>`', value: '`unmutes a previously muted member`'}
)
.setColor('#FFC300')
const sendembed1 = await message.channel.send(embed1)
const nextemoji = '▶'
const lastemoji = '◀'
sendembed1.react(lastemoji)
sendembed1.react(nextemoji)
const filter = (reaction, user) => {
return ['▶', '◀'].includes(reaction.emoji.name) && user.id === message.author.id
}
sendembed1.awaitReactions(filter, {max:1, time:60000, error: ["time"]}).then(
async (collected) => {
const reaction = collected.first()
const embed2 = new Discord.MessageEmbed()
.setTitle('Math commands')
.setDescription('Please type . before every command to use it ')
.addFields(
{name: '`.add <num1> <num2>`', value: '`adds 2 numbers and returns the sum`'},
{name: '`.sub <num1> <num2>`', value: '`subtracts 2 numbers and returns the difference`'},
{name: '`.multiply <num1> <num2>`', value: '`multiplies 2 numbers and returns the product`'},
{name: '`.divide <num1> <num2>`', value: '`divides 2 numbers and returns the quotient`'}
)
.setColor('#FFC300')
if(reaction.emoji.name === '▶') {
sendembed1.edit(embed2)
}
}
)
}
}
This works and now all I want to do is make or add 2 more pages but I am not sure where to put the code to make that work.这行得通,现在我要做的就是制作或添加另外 2 个页面,但我不确定将代码放在哪里才能使其正常工作。
The way you're doing this is a bit hard.你这样做的方式有点难。 Try using an array or something.
尝试使用数组或其他东西。
Example:例子:
const Discord = require('discord.js')
let pages = [];
let page = 0;
//I'll do it normally.
//You can use array.append()
pages[0] = new Discord.MessageEmbed()
.setDescription("Homepage")
pages[1] = new Discord.MessageEmbed()
.setDescription("Another page")
//And many more
//...
message.channel.send(pages[0])
.then(msg => {
msg.react('⬅').then( r => {
msg.react('➡')
// Filters (I'll use arrow functions)
const backwardsFilter = (reaction, user) => { reaction.emoji.name === '⬅' && user.id === message.author.id }
const forwardsFilter = (reaction, user) => { reaction.emoji.name === '➡' && user.id === message.author.id }
const backwards = msg.createReactionCollector(backwardsFilter, {timer: 6000})
const forwards = msg.createReactionCollector(forwardsFilter, {timer: 6000})
backwards.on('collect', (r, u) => {
if(page === 0){ return r.users.remove(r.users.cache.filter(u => u === message.author).first()) } //The first aka Home page
page --
msg.edit(pages[page])
return r.users.remove(r.users.cache.filter(u => u === message.author).first())
});
forwards.on('collect', (r, u) => { //r = reaction; u = user
if(page === (pages.length - 1)){ return r.users.remove(r.users.cache.filter(u => u === message.author).first())} //The last page
page++
embed.setDescription(pages[page-1])
msg.edit(pages[page]);
return r.users.remove(r.users.cache.filter(u => u === message.author).first())
});
});
});
Now put this thing in your execute
function.现在把这个东西放在你的
execute
function 中。 You might change the embeds according to your needs您可以根据需要更改嵌入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.