[英]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.