【发布时间】:2022-01-21 09:17:37
【问题描述】:
我有从用户收集消息的斜杠命令。用户输入游戏中的昵称,bot 应返回embeded 2 队。我设法过滤和收集昵称,并调用计算函数。如果我输入最大数量的昵称,这将起作用,但现在我想添加功能,我将通过发送消息“停止”手动停止收集。现在我不知道在哪里添加条件
if(m.content==="stop") {collector.stop();}
const { SlashCommandBuilder } = require("@discordjs/builders");
const { getSummonerProfile } = require("./../functions/summonerData");
const { MessageEmbed } = require("discord.js");
let arrayOfSummoners = [];
let arrayOfNicknames = [];
async function checkIfSummonerExist(m) {
const test = await getSummonerProfile(m.content);
if (test && m.author.bot == false && !arrayOfNicknames.includes(m.content)) {
m.react("????");
return true;
} else if (test == false && m.author.bot == false) {
m.react("????");
return false;
}
if (arrayOfNicknames.includes(m.content)) {
m.react("????");
}
}
module.exports = {
data: new SlashCommandBuilder()
.setName("custom")
.setDescription("Enter the name of the user."),
async execute(interaction) {
await interaction.deferReply();
interaction.editReply("Insert users");
const exampleEmbed = new MessageEmbed()
.setColor("#0099ff")
.setTimestamp();
// `m` is a message object that will be passed through the filter function
const filter = (m) => checkIfSummonerExist(m);
const collector = interaction.channel.createMessageCollector({
filter,
max: 4,
});
if(m.content==="stop")
{
collector.stop();
}
collector.on("collect", (m) => {
arrayOfNicknames.push(m.content);
exampleEmbed.addFields({
name: "Regular field title",
value: m.content, inline:true
});
});
collector.on("end", (collected) => {
interaction.followUp({ embeds: [exampleEmbed] });
});
},
};
如果我在filter fuction (checkIfSummonerExist(m) 中添加此条件,我会收到错误collector is not defined,如果在execute 中调用它,就像上面的示例一样,我会收到错误m is not defined
【问题讨论】:
标签: javascript discord.js