我想要存档的内容...
我正在try 为我的discord bot创建一个猜测命令处理程序.它将从数组中随机选取一个项目,用户需要根据一些提示在1分钟内猜测所选单词.
问题
命令处理程序只允许运行一次特定代码,因此它不会检测用户是否回复.因此,我无法检测用户是否在特定时间内回复了来自机器人的特定消息.
密码
// Copyright © 2022 <copyright holders>
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const Discord = require("discord.js");
const { prefix, colors } = require("./../utils/config.json");
const embedColor = colors.default;
const embedError = colors.error;
module.exports = {
name: "guess",
description: "Find a secret animal by following the hints to get reputation.",
aliases: ["?", "h"],
usage: "[prefix] + ping",
guildOnly: false,
args: false,
slash: true,
permissions: {
bot: [],
user: [],
},
execute: async (message, args, client) => {
const { commands } = message.client;
function question() {
// Sending message
const animals = ["pig", "elephant", "shark", "dog", "cat", "lion", "wolf", "bee", "snake", "bird"];
const random = Math.floor(Math.random() * animals.length);
const random_choice = (animals[random]);
// msg2 = message.channel.send("See or Change?");
// if (msg2.type === 'REPLY')
// console.log(msg1.content);
let filter = m => m.author.id === message.author.id
message.channel.send(`Are you sure to delete all data? \`YES\` / \`NO\``).then(() => {
message.channel.awaitMessages(filter, {
max: 1,
time: 10000,
errors: ['time']
})
.then(message => {
message = message.first();
if (message.content.toLowerCase() == random_choice) {
message.channel.send(`Got it right`)
} else {
message.channel.send('The Animal was: `' + random_choice + '`!')
}
})
.catch(collected => {
message.channel.send('Timeout');
});
})
}
let { channel, reference: reply } = message
const cmdHelpEmbed = new Discord.MessageEmbed()
.setTitle("**PING**")
.setDescription(`Hey, ` + message.author.username + `! I am ready to play guess game`)
.setColor(embedColor)
.addFields(
{
name: 'How to play?',
value: 'This game is simple, I will select a random animal and give you 3 hints. You just need to find the correct animal to win reputation. To answer reply to this message, within 1 minute'
}, {
name: '\u200B',
value: '**RULES**'
}, {
name: 'Rule 1:',
value: 'No Cheating',
inline: true
},
{
name: 'Rule 2:',
value: 'Have fun!',
inline: true
},
);
message.channel.send({
embeds: [cmdHelpEmbed],
});
var delayInMilliseconds = 5000; // 5 seconds
setTimeout(function() {
question();
}, delayInMilliseconds);
},
};