【发布时间】:2021-08-02 23:49:07
【问题描述】:
我想转换它,以便人们只需要做出反应并将应用程序发送给他们,我不知道如何在反应的东西上发送消息,所以如果有人可以帮助我,将不胜感激。
两个非常乐于助人的人帮助了我
@Skulaurun Mrusal 和 @PerplexingParadox
谢谢! ????
client.on("message", async (message) => {
// Don't reply to bots
if (message.author.bot) return;
if (message.content == "#req") {
if(!message.member.hasPermission("MANAGE_MESSAGES"))
{
message.reply("You do not have permission to do that!");
return;
}
// Perform raw API request and send a message with a button,
// since it isn't supported natively in discord.js v12
client.api.channels(message.channel.id).messages.post({
data: {
embeds: [reqEmbed],
components: [
{
type: 1,
components: [
{
type: 2,
style: 4,
label: "Apply",
// Our button id, we can use that later to identify,
// that the user has clicked this specific button
custom_id: "send_application"
}
]
}
]
}
});
}
});
// Channel id where the application will be sent
const applicationChannelId = "652099170835890177";
// Our questions the bot will ask the user
const questions = [
"What is your In-Game Username?",
"How long have you been drifting on FiveM?",
"Do you use Controller or Keyboard?",
"How much do you play weekly?",
"Have you been in any other teams? If so, why did you leave?",
"Short description about yourself and why you would like to be apart of Blind Spot? (Age, Country)"
];
// Function that will ask a GuildMember a question and returns a reply
async function askQuestion(member, question) {
const message = await member.send(question);
const reply = await message.channel.awaitMessages((m) => {
return m.author.id === member.id;
}, { time: 5 * 60000, max: 1 });
return reply.first();
}
client.ws.on("INTERACTION_CREATE", async (interaction) => {
// If component type is a button
if (interaction.data.component_type === 2) {
const guildId = interaction.guild_id;
const userId = interaction.member.user.id;
const buttonId = interaction.data.custom_id;
const member = client.guilds.resolve(guildId).member(userId);
if (buttonId == "send_application") {
// Reply to an interaction, so we don't get "This interaction failed" error
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: "I have started the application process in your DM's.",
flags: 64 // make the message ephemeral
}
}
});
try {
// Create our application, we will fill it later
const application = new MessageEmbed()
.setTitle("New Application")
.setDescription(`This application was submitted by ${member.user.tag}`)
.setColor("#ED4245");
const cancel = () => member.send("Your application has been canceled.\n**If you would like to start your application again Click on the Apply button in** <#657393981851697153>");
// Ask the user if he wants to continue
const reply = await askQuestion(member,
"Please fill in this form so we can proceed with your tryout.\n" +
"**Type `yes` to continue or type `cancel` to cancel.**"
);
// If not cancel the process
if (reply.content.toLowerCase() != "yes") {
cancel(); return;
}
// Ask the user questions one by one and add them to application
for (const question of questions) {
const reply = await askQuestion(member, question);
// The user can cancel the process anytime he wants
if (reply.content.toLowerCase() == "cancel") {
cancel(); return;
}
application.addField(question, reply);
}
await askQuestion(member,
"Do you want your application to be submitted?\n" +
"**Type `yes` to get your Application submitted and reviewed by Staff Members**"
);
// If not cancel the process
if (reply.content.toLowerCase() != "yes") {
cancel(); return;
}
// Send the filled application to the application channel
client.channels.cache.get(applicationChannelId).send(application);
} catch {
// If the user took too long to respond an error will be thrown,
// we can handle that case here.
member.send(
"You took too long to respond or Something went wrong, Please contact a Staff member\n" +
"The process was canceled."
);
}
}
}
});
【问题讨论】:
-
这就是Callback Hell的定义:P
标签: javascript discord discord.js