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
496 views
in Technique[技术] by (71.8m points)

javascript - discord.js机器人对其自身进行回复(discord.js bot replies to itself)

I am currently coding my first discord bot, it can already play YouTube music.(我目前正在编写我的第一个Discord机器人,它已经可以播放YouTube音乐。)

if (message.content.includes("Good Job") || message.content.includes("good job")) { message.channel.sendMessage("Good Job everyone :smirk:"); } As you see, if someone types "good job" (this is just an example) then the bot will reply with "good job everyone :smirk:), but then the spam will begin: the bot reads his own message and replies to it.(如您所见,如果有人键入“好工作”(这只是一个例子),则该机器人将以“每个人都好工作:smirk :)进行回复,但垃圾邮件将开始:该机器人读取自己的消息并对其进行回复。) How can I prevent the bot from answering itself?(如何防止漫游器自行回答?)   ask by gitgudgithub translate from so

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

1 Reply

0 votes
by (71.8m points)

Use this in the on message event:(在on消息事件中使用此命令:)

if (message.author.bot) return; for more info: https://anidiotsguide.gitbooks.io/discord-js-bot-guide/coding-guides/a-basic-command-handler.html(有关更多信息: https : //anidiotsguide.gitbooks.io/discord-js-bot-guide/coding-guides/a-basic-command-handler.html)

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

...