[英]I am trying to open my discord bot . But it shows me this message . I have discord.js installed
[英]I have an error that I do not understand. It is in Discord.js, and I am making a bot that does things only for my server. I am new to discord.js :)
我正在制作一個只能在特定服務器上運行的機器人。 服務器是關於交易卡的,我想做一些基本的東西,可以緩和,人們可以玩得開心。 即使你沒有解決我的錯誤,你也可以給我一些關於機器人的想法。 非常感謝,z4a。
錯誤如下所示:
c:\Users\REDACTED\Desktop\Sky\index.js:10
if (message.content === 'sky claim') {
^
ReferenceError: message is not defined
at Client.<anonymous> (c:\Users\kelly\Desktop\Sky\index.js:10:3)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (c:\Users\REDACTED\Desktop\Sky\node_modules\ws\lib\websocket.js:845:20)
我的多用途交易卡機器人的代碼在這里。
require("events").EventEmitter.defaultMaxListeners = 15;
const Discord = require("discord.js");
const client = new Discord.Client();
client.login("nope lol");
client.on("ready", () => {
console.log("Sky connected to node.js servers");
console.log("Console connected, logged in as $[client.user.tag}.");
});
client.on("message", (msg) => {
if (message.content === "sky claim") {
message.channel.send("${message.author} claimed 250 SkyBucks. Spend SkyBucks on colored roles.");
console.log("${message.author} executed command successfully");
}
});
client.on("message", (msg) => {
if (message.content === "sky twitter") {
message.channel.send("Our twitter channel is @RippinCardPacks, I will drop a link.");
message.channel.send("https://twitter.com/rippincardpacks");
}
});
client.on("message", (msg) => {
if (message.content === "sky eBay") {
message.channel.send("Our eBay store is @CollectAmazing, I will drop a link:");
message.channel.send("https://www.ebay.com/str/collectamazing");
}
});
client.on("message", (msg) => {
if (message.content === "sky react") {
message.channel.send("Reacting to your message with a little smiley face...");
message.react("😄");
}
});
client.on("message", (msg) => {
if (message.content === "sky botcreator") {
message.channel.send("@z4 made this bot");
}
});
client.on("message", (msg) => {
if (message.content === "sky socials") {
message.author.send("Hey! Just a quick reminder to check out our Twitter channel, and the eBay store.");
message.author.send("https://www.twitter.com/rippincardpacks");
message.author.send("https://www.ebay.com/sch/i.html?_nkw=collectamazing");
}
});
client.on("message", (msg) => {
if (message.content === "ping") {
message.channel.send("pong");
}
});
client.on("guildMemberAdd", (member) => {
const channel = member.guild.channels.cache.find((ch) => ch.name === "member-log");
if (!channel) return;
channel.send(`Welcome to the server, ${member}. Make sure to check out our eBay store and our Twitter store by using commands "sky twitter", and "sky eBay". `);
});
client.on("message", (message) => {
if (message.content === "sky avatar") {
message.reply(message.author.displayAvatarURL());
}
});
client.on("message", (message) => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
// If the message content starts with "sky kick"
if (message.content.startsWith("sky kick")) {
// Assuming we mention someone in the message, this will return the user
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
const user = message.mentions.users.first();
// If we have a user mentioned
if (user) {
// Now we get the member from the user
const member = message.guild.member(user);
// If the member is in the guild
if (member) {
/**
* Kick the member
* Make sure you run this on a member, not a user!
* There are big differences between a user and a member
*/
member
.kick("Optional reason that will display in the audit logs")
.then(() => {
// We let the message author know we were able to kick the person
message.reply(`Successfully kicked ${user.tag}`);
})
.catch((err) => {
// An error happened
// This is generally due to the bot not being able to kick the member,
// either due to missing permissions or role hierarchy
message.reply("I was unable to kick the member");
// Log the error
console.error(err);
});
} else {
// The mentioned user isn't in this guild
message.reply("That user isn't in this guild!");
}
// Otherwise, if no user was mentioned
} else {
message.reply("You didn't mention the user to kick!");
}
}
});
client.on("message", (message) => {
// Ignore messages that aren't from a guild
if (!message.guild) return;
// if the message content starts with "sky ban"
if (message.content.startsWith("sky ban")) {
// Assuming we mention someone in the message, this will return the user
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
const user = message.mentions.users.first();
// If we have a user mentioned
if (user) {
// Now we get the member from the user
const member = message.guild.member(user);
// If the member is in the guild
if (member) {
/**
* Ban the member
* Make sure you run this on a member, not a user!
* There are big differences between a user and a member
* Read more about what ban options there are over at
* https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
*/
member
.ban({
reason: "They were bad!",
})
.then(() => {
// We let the message author know we were able to ban the person
message.reply(`Successfully banned ${user.tag}`);
})
.catch((err) => {
// An error happened
// This is generally due to the bot not being able to ban the member,
// either due to missing permissions or role hierarchy
message.reply("I was unable to ban the member");
// Log the error
console.error(err);
});
} else {
// The mentioned user isn't in this guild
message.reply("That user isn't in this guild!");
}
} else {
// Otherwise, if no user was mentioned
message.reply("You didn't mention the user to ban!");
}
}
});
client.on("message", (message) => {
if (message.content === "sky play rickroll") {
var VC = message.member.voiceChannel;
if (!VC)
return message
.reply("You are not in a voice channel, please join one, then re-execute this command.")
.then((connection) => {
const dispatcher = connection.playFile("c:/users/kelly/desktop/sky/music_cmd_files/rickroll.m4a");
dispatcher.on("end", (end) => {
VC.leave();
});
})
.catch(console.error);
}
});
非常感謝,我真的需要這個機器人運行,因為我爸爸運行這個不和諧服務器,我 12 歲,幫助他的服務器(主要是調節它並保持活躍)所以我可以打開免費的口袋妖怪盒子,並出售卡片為了更多的錢。 第三次,我喜歡堆棧溢出幫助社區,非常感謝。 z4a
如果您閱讀錯誤,您應該能夠找出它不起作用的原因:
client.on('message', message => {
if (message.content === 'sky eBay') {
message.channel.send('Our eBay store is @CollectAmazing, I will drop a link:');
message.channel.send('https://www.ebay.com/str/collectamazing');
}
})
將所有的client.on('message', msg
改為client.on('message', message
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.