Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

javascript - 我的不和谐机器人一次又一次地重复该语句,该如何解决?(My discord bot repeats the statement again and again, how to fix that?)

**I am trying to make a discord.js bot like invitemanager that will give the invites of a user in server.(**我正在尝试制作一个邀请用户管理器之类的discord.js机器人,该机器人将邀请用户。)

If I can get a alternative code that will be also fine, i surfed all over the internet but not found any source code of invite manager or something like that, please anyone resolve my problem.(如果我能得到一个也可以的替代代码,则我在Internet上进行了网上冲浪,但没有找到邀请管理器或类似内容的任何源代码,请任何人解决我的问题。) That invite manager bot sucks that's why i wanna make my own bot which will manage invites in my server.(邀请管理器机器人很烂,这就是为什么我要制作自己的机器人来管理服务器中的邀请的原因。) Currently i got this code but it just repeat over and over again and also the commandtrigger isn't working.(目前,我得到了这段代码,但是它只是一遍又一遍地重复,而且命令触发程序也无法正常工作。) The commands starts executing in whatever you typed.(命令以您键入的任何内容开始执行。) Please give a solution for that.(请为此提供解决方案。) Thanks in advance**(提前致谢**) const client = new Discord.Client(); let activenum = 0; client.on('ready', () => { client.user.setStatus('available') client.user.setPresence({ game: { name: '??? ???????? ??', type: "STREAMING", url: "https://www.youtube.com/watch?v=-mTkE8YJEPU" } }); }); var prefix = "-" var adminprefix = '-' //bc client.on('message', message => { if(message.content === '-invite') var targetUser = null; var isAnotherUserLookup = false; if(message.mentions.members.first() != null) { targetUser = message.mentions.members.first(); isAnotherUserLookup = true; } else targetUser = message.member; message.guild.fetchInvites() .then (invites => {var targetUser = null; var isAnotherUserLookup = false; if(message.mentions.members.first() != null) { targetUser = message.mentions.members.first().user; console.log(targetUser.user); isAnotherUserLookup = true; } else targetUser = message.author; message.guild.fetchInvites() .then (invites => { const userInvites = invites.array().filter(o => o.inviter.id === targetUser.id); var userInviteCount = 0; if(isAnotherUserLookup) message.channel.send(`User _${targetUser.username}_ has invited ${userInviteCount} user(s) to this server.`); else message.reply(`You have invited ${userInviteCount} user(s) to this server. Keep up the good work!`); return; } ) } ) }); client.login(process.env.token);``` https://glitch.com/~colossal-trumpet   ask by SKITTER translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your if statement doesn't have curly braces;(您的if语句没有大括号;)

Meaning that it will only be applied to the line after it.(意味着它将仅应用于它之后的行。) This means that you don't actually have a command filter to determine when the bot sends the invite messsage.(这意味着您实际上没有命令过滤器来确定漫游器何时发送邀请消息。) The bot will just send the invite message each time it recieves any message (including from itself!)(该机器人每次收到任何消息(包括自身发出的消息)时,只会发送邀请消息。) Read more about it here .(在此处了解更多信息。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...