![](/img/trans.png)
[英]My Discord.js bot is running (online and shows in console) but it won't respond to commands
[英]My Discord.js is running but won't respond to commands
我想為我的不和諧服務器制作一個建議機器人,所以我在人們做“!建議”時進行編碼,機器人會編寫一種舒適的方式讓人們投票支持該建議,但由於某種原因機器人不會響應,我檢查了類似的問題這發生在其他人身上,但解決方案對我不起作用。
這是代碼:
const { MessageEmbed } = require("discord.js")
module.exports = {
name: "suggest",
usage: "suggest <message>",
description: "Send your Suggestion",
category: "main",
run: (client, message, args) => {
if(!args.length) {
return message.channel.send("Please Give the Suggestion")
}
let channel = message.guild.channels.cache.find((x) => (x.name === "suggestion" || x.name === "suggestions"))
if(!channel) {
return message.channel.send("there is no channel with name - suggestions")
}
let embed = new MessageEmbed()
.setAuthor("SUGGESTION: " + message.author.tag, message.author.avatarURL())
.setThumbnail(message.author.avatarURL())
.setColor("#ff2050")
.setDescription(args.join(" "))
.setTimestamp()
channel.send(embed).then(m => {
m.react("✅")
m.react("❌")
})
message.channel.send("Sended Your Suggestion to " + channel)
}
}
修復主要錯誤
在第 11 行,您輸入了if (!args.length) {
。
這會給你一個未定義的錯誤,導致你的其余代碼無法工作。
用以下代碼替換該行:
if(args.length < 1) {
return message.channel.send("Please provide the Suggestion")
}
修復拼寫錯誤
當您在代碼末尾發送最終消息時
message.channel.send("Sended Your Suggestion to " + channel)
“已發送”不是一個詞,應替換為“已發送”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.