【发布时间】:2021-03-23 11:07:09
【问题描述】:
现在,我有一个 Discord 机器人,可以为游戏设置“注册”。
我正在寻找的是让用户能够发送消息“+join (class)”来注册一个插槽。因此,如果我说“+join Soldier”,它会将我的名字放在插槽中,如下所示:
如果所有名额都已满或工作人员键入“+close”,它将关闭当前游戏的注册。我知道我必须使用 .edit 函数将嵌入替换为相同的新嵌入,但用户名已放入插槽中,但我真的不知道该怎么做,特别是因为这涉及两个单独的 javascript 文件。我真的很感激所有的帮助。太感谢了! :)
NewGameCommand.js:
const Discord = require('discord.js');
module.exports = class NewgameCommand extends BaseCommand {
constructor() {
super('newgame', 'managment', []);
}
async run(client, message, args) {
if (!message.member.hasPermission("MANAGE_ROLES")) {
return message.channel.send("Only staff members can set up games!");
}
let gameEmbed = new Discord.MessageEmbed()
.setTitle('')
.setDescription('')
.setColor("#FF0000")
const twoCitiesMissionsDisplayed = "\`\`\`\n1 - ????Empire Escalation\n2 - ????Metro Malice\n3 - ????Hamlet Hostility\n4 - ????Bavarian Botbash\`\`\`";
const twoCitiesMissionsArray = ['????Empire Escalation', '????Metro Malice', '????Hamlet Hostility', '????Bavarian Botbash'];
const numOfMissions = ['1', '2', '3', '4'];
const cancelWords = ['cancel', 'quit', 'stop', '+cancel', '+quit', '+stop'];
const mvmChannel = client.channels.cache.get('787130524703129611');
let classMapDefault = new Map();
classMapDefault['Soldier'] = '';
classMapDefault['Demo/Pyro'] = '';
classMapDefault['Heavy'] = '';
classMapDefault['Medic'] = '';
classMapDefault['Engineer'] = '';
classMapDefault['Scout'] = '';
const filter = m => m.author.id === message.author.id;
message.reply("which Two Cities mission?");
message.channel.send(twoCitiesMissionsDisplayed);
message.channel.awaitMessages(filter, {max: 1, time: 30000}).then(collected => {
if(cancelWords.includes(collected.first().content)) {
return message.channel.send("Canceled.");
}
let missionNumString = collected.first().content;
// if they don't choose 1, 2, 3 or 4
if(!numOfMissions.includes(missionNumString)) {
return message.channel.send("Invalid mission number!")
}
let missionNum = parseInt(missionNumString) - 1;
let missionName = twoCitiesMissionsArray[missionNum];
message.channel.send(`Great, we'll be playing the ${missionName} mission this week! Are we playing with the default class set? (yes/no)`);
message.channel.awaitMessages(filter, {max: 1, time: 30000}).then(collected => {
if(cancelWords.includes(collected.first().content)) {
return message.channel.send("Canceled.");
}
let classResponseArray = collected.first().content;
let classResponse = classResponseArray[0].toLowerCase();
if (classResponse.charAt(0) === 'y') {
let classMap = classMapDefault;
const class1 = 'Soldier';
const class2 = 'Demo/Pyro';
const class3 = 'Heavy';
const class4 = 'Medic';
const class5 = 'Engineer';
const class6 = 'Scout';
message.channel.send('Got it! What time? (PST)\nFormat it like \`6:30\` or \`7:00\`');
message.channel.awaitMessages(filter, {max: 1, time: 30000}).then(collected => {
if(cancelWords.includes(collected.first().content)) {
return message.channel.send("Canceled.");
}
let timeResponse = collected.first().content;
gameEmbed.setTitle(`New MvM Mondays Game! This Monday @ ${timeResponse} PST.`);
let gameDescription = `Tour: ????️Two Cities\nMission: ${missionName}\n`
let class1description = `${class1}: open⭕\n`
let class2description = `${class2}: open⭕\n`
let class3description = `${class3}: open⭕\n`
let class4description = `${class4}: open⭕\n`
let class5description = `${class5}: open⭕\n`
let class6description = `${class6}: open⭕\n`
gameDescription = gameDescription + '\`\`\`' + class1description + class2description + class3description + class4description + class5description + class6description + "\`\`\`";
gameEmbed.setDescription(gameDescription);
let openOrClosed = `OPEN????`;
gameEmbed.setFooter(`Sign-ups: ${openOrClosed}`);
message.channel.send(`${timeResponse} it is! Here's what will be sent to ${mvmChannel}:`);
message.channel.send(gameEmbed);
message.channel.send('Ready to send? Type \"yes\" to send or \"no\" to cancel.');
message.channel.awaitMessages(filter, {max: 1, time: 30000}).then(collected => {
if(cancelWords.includes(collected.first().content)) {
return message.channel.send("Canceled.");
}
let sendResponseArray = collected.first().content;
let sendResponse = sendResponseArray[0].toLowerCase();
if (sendResponse.charAt(0) === 'y') {
mvmChannel.send(gameEmbed);
message.send(`MvM Mondays Sign-up created in ${mvmChannel}!`);
} else if (sendResponse.charAt(0) === 'n') {
message.channel.send("Canceled.");
} else {
return message.reply('you just had to say \"yes\" or \"no\"!');
}
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err)
})
} else if (classResponse.charAt(0) === 'n') {
return message.channel.send('I only know the default class sets right now...');
} else {
return message.reply('you just had to say \"yes\" or \"no\"!');
}
}).catch(err => {
console.log(err)
})
}).catch(err => {
console.log(err)
})
}
}
JoinCommand.js:
const BaseCommand = require('../../utils/structures/BaseCommand');
const Discord = require('discord.js');
module.exports = class JoinCommand extends BaseCommand {
constructor() {
super('join', 'member', []);
}
run(client, message, args) {
const mvmClass = args[0];
message.channel.send(message.author.toString() + ` joined as ${mvmClass}!`);
}
}
【问题讨论】:
标签: javascript string discord discord.js