【发布时间】:2021-03-29 18:08:45
【问题描述】:
我想知道是否有可能有一个命令只能由不和谐的用户使用一次,如果可以,请有人给我代码,我将不胜感激。
【问题讨论】:
标签: discord.js bots
我想知道是否有可能有一个命令只能由不和谐的用户使用一次,如果可以,请有人给我代码,我将不胜感激。
【问题讨论】:
标签: discord.js bots
首先,SO 不是一个代码即服务平台或其他任何东西。你提供代码,你告诉你的问题,我们帮助你。它是这样工作的。这是我的答案。
当然,是的,这是可能的。任何基于逻辑的东西都可以被计算机复制。你只需要学习如何像计算机一样思考。在您的情况下,它看起来像伪代码。
when the command is received:
has the user already used this command?
yes:
return "You've already used this command!"
no:
do the work
您需要保存已使用该命令的用户。为简单起见,您要使用的数据库将表示为一个数组。
let blockList = []
client.on('message', msg => {
if (msg.content === "!command") {
if (blockList.includes(msg.author.id)) return msg.reply("You've already used this command!");
msg.reply("This is the first time you're using this command! You won't be able to do it again. BUT since the blocklist is stored as an array, the list will be cleared when the program will stop.")
return blockList.push(msg.author.id)
}
})
这里有逻辑。您可以将其与您的数据库集成到您的代码中。 我希望我能帮上忙,请不要发布另一个类似的问题。尝试、搜索和询问!能帮到你会更好,我相信你会学到更多。
【讨论】: