【发布时间】:2021-10-14 01:35:00
【问题描述】:
我创造了一个真心话大冒险的机器人。我的前缀是 + 现在我想向它添加一条错误消息。我有两个变量 "t" "d" 如果有人键入 +something 与我的变量不匹配以发送消息“无效命令 +help for Help” 你们能帮帮我吗?
const Discord = require('discord.js');
const client = new Discord.Client();
const keepAlive = require("./server")
const prefix = "+";
// ======== Ready Log ========
client.on ("ready", () => {
console.log('The Bot Is Ready!');
client.user.setPresence({
status: 'ONLINE', // Can Be ONLINE, DND, IDLE, INVISBLE
activity: {
name: 'Truth Or Dare | +help',
type: 'PLAYING', // Can Be WHATCHING, LISTENING
}
})
});
// ======== Code ========
client.on('message', message => {
const help = new Discord.MessageEmbed()
.setColor('#72dfa3')
.setTitle(`Truth Or Dare`)
.addFields(
{ name: '``+help``', value: 'For help'},
{ name: '``+t``', value: 'For Truth'},
{ name: '``+d``', value: 'For Your Dare'},
{ name: '``Created By``', value: 'AlpHa Coder [Labib Khan]'},
)
.setTimestamp()
.setFooter(`${message.author.username}`, message.author.displayAvatarURL());
if (message.content === `${prefix}help`) {
message.channel.send(help);
}
});
// ========= Truth =========
client.on('message', message => {
const t = [
"If you could be invisible, what is the first thing you would do?",
"What's the strangest dream you've ever had?",
"What are the top three things you look for in a boyfriend/girlfriend?",
"What is your worst habit?",
"How many stuffed animals do you own?",
"What is your biggest insecurity?"
]
const truth = t[Math.floor(Math.random() * t.length)];
if (message.content === `${prefix}t`) {
message.channel.send(truth);
}
});
// ========= Dare =========
client.on('message', message => {
const d = [
"Do a free-style rap for the next minute.",
"Let another person post a status on your behalf.",
"Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
"Let the other players go through your phone for one minute.",
"Smell another player's armpit",
"Smell another player's barefoot.",
"Tell everyone your honest opinion of the person who sent this command."
]
const dare = d[Math.floor(Math.random() * d.length)];
if (message.content === `${prefix}d`) {
message.channel.send(dare);
}
});
const token = process.env.TOKEN;
keepAlive()
client.login(token);
请解释清楚,以便我理解。提前谢谢
【问题讨论】:
-
您通过调用多个 client.on('message', (msg)=>{}); 犯了一个巨大的错误这将被调用一次以处理通过您的客户端的所有消息。
-
如果我在下面的回答解决了您在问题中提出的问题,您应该考虑通过单击复选标记将其标记为已接受。
标签: javascript discord discord.js