【发布时间】:2020-09-26 22:18:06
【问题描述】:
对于不和谐机器人,我完全是个菜鸟,但我正在尽我最大的努力学习,并尽我所能。我正在尝试编写一个机器人,让您在频道中进行测试。如果您解决了 4/5 的问题,您将获得一个特殊的角色。如果一个用户在做这件事似乎可以正常工作,但是一旦有 2 个或更多用户尝试同时进行测验,问题的答案就会出错,并且发送到频道的问题数量也可能会有所不同我不知道为什么。据我了解,一旦输入消息,消息变量就会被覆盖。但就我而言,javascript 在单个线程上运行,所以我不明白为什么会这样。如果有人能够帮助我和/或有一些建设性的批评,我将很高兴。 :)
const meineid = '202469056668762113'
const quiz = require('../quiz.json')
const standartEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
module.exports = {
name: 't',
description: 't',
execute(message, client) {
let x = message.member.roles.cache.find(role => role.name === 'Regeln')
if (x===undefined) {
assign(message, client)}
else {message.channel.send("bruder was los mit dir")}
}
}
async function assign (message, client) {
if (message.guild.channels.cache.find(c => c.name === message.author.id)) {
message.reply("Channel existiert bereits")
}
else {
await message.guild.channels.create(message.author.id, {
type: 'text',
permissionOverwrites: [
{
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
},
{
id: meineid,
allow: ['VIEW_CHANNEL'],
},
{
id: client.user.id,
allow: ['VIEW_CHANNEL'],
},
{
id: message.author.id,
deny: ['SEND_MESSAGES'],
allow: ['VIEW_CHANNEL'],
},
],
})
message.guild.channels.cache.find(c => c.name === message.author.id).send("<@" + message.author.id + ">")
test(message)
standartEmbed.fields = []
message.guild.channels.cache.find(c => c.name === 'bot-log').send(standartEmbed
.addFields(
{ name: "Created channel: ", value: message.author.id },
)
.setTimestamp())
}
}
async function test(message) {
let y=0
for (z=0; z < 5; z++) {
let i = Math.floor(Math.random() * quiz.length)
item = quiz[i]
quiz.splice(i, 1)
const reactions = ['????','????','????']
const quizEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
const filter = (reaction, user) => {
return reactions.includes(reaction.emoji.name) && user.id === message.author.id
}
await message.guild.channels.cache.find(c => c.name === message.author.id.toString()).send(quizEmbed
.setTitle(item.question)
.addFields(
{ name: reactions[0], value: item.options[0] },
{ name: reactions[1], value: item.options[1] },
{ name: reactions[2], value: item.options[2] },
)
.setTimestamp()
)
.then(async function(message) {
reactions.forEach(r => message.react(r))
await message.awaitReactions(filter, {max:1, time: 11110000})
.then(function(collected) {
if (collected.first().emoji.name == item.answer) {
message.channel.send("Richtig! :)")
y++
return y
} else message.channel.send("Falsch! :(")
return y
}).catch(collected => {
z=5
})
return y
})
}
}```
【问题讨论】:
标签: javascript node.js bots discord discord.js