【发布时间】:2021-04-18 16:13:06
【问题描述】:
所以基本上我有这个很好用的赠品命令,但如果你在你设置的时间完成后对表情符号做出反应,它只会发送“没有足够的人对我做出反应以抽出获胜者,它不会选择获胜者”不知道为什么会这样。
client.on('message', async message =>{
if(message.content.toLowerCase().startsWith(prefix + 'giveaway')) {
if(!message.member.hasPermission("MANAGE_MESSAGES"))
return message.channel.send('You cant use this command sice youre missing `manage_messages` perm')
let args = message.content.substring(prefix.length).split(" ")
let time = args[1]
if(!time) return message.channel.send('You did not specify your time');
if(
!args[1].endsWith("d") &&
!args[1].endsWith("h") &&
!args[1].endsWith("m") &&
!args[1].endsWith("s")
)
return message.channel.send("You need to use d (days), h (hours), m (minutes), or s (seconds)")
let gchannel = message.mentions.channels.first();
if(!gchannel) return message.channel.send("I cant find that channel in the server.")
let prize = args.slice(3).join(" ")
if(!prize) return message.channel.send('What is the prize?')
message.delete()
gchannel.send(`:tada: **New Giveaway** :tada:`)
const newEmbed = new Discord.MessageEmbed()
.setTitle('New Giveaway')
.setColor("RANDOM")
.setDescription(`React with :tada: to enter the giveaway.
\nHosted By: **${message.author}** \nTime: **${time}**\nPrize: **${prize}**`)
.setFooter(`Will end in ${time}`)
let reaction = await gchannel.send(newEmbed)
reaction.react("????")
setTimeout(() => {
if ((m) => m.reaction.cache.get("????").count <= 0) {
return message.channel.send("Not enough people reacted for me to draw a winner")
}
let winner = (m) => m.reaction.cache.get("????").users.cache.filter((u) => !u.bot).random();
gchannel.send(`Congratulations ${winner} You just won the **${prize}**!`
);
}, ms(args[1]));
}
})
【问题讨论】:
-
m来自哪里?你不能那样做。您需要获取带有反应的实际消息对象 (reaction) -
我该怎么做?
-
您已经在
reaction变量中拥有它 -
idk 改变什么或改变什么
-
好吧,
.send()返回一个包含 Message 对象的 Promise,该对象具有reactions属性
标签: javascript discord discord.js