执行此代码时出错:
const now = new Date();
bot.on("guildMemberRemove", member => {
console.log(member.user.username + ' left from a Server at ' + now + `Just watch the logs on the server`)
});
有帮助吗? :-) 问候,祝你有个愉快的一天!
编辑:
const commando = require('discord.js-commando');
const bot = new commando.Client();
const now = new Date();
bot.registry.registerGroup('random', 'Random');
bot.registry.registerGroup('reply', 'Reply');
bot.registry.registerDefaults();
bot.registry.registerCommandsIn(__dirname + "/commands")
bot.on("ready", () => {
console.log(`Bot has started, with ${bot.users.size} users, in ${bot.channels.size} channels of ${bot.guilds.size} guilds.`);
bot.user.setActivity(`Serving ${bot.guilds.size} servers`);
});
bot.on("guildCreate", guild => {
console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
bot.user.setActivity(`Serving ${bot.guilds.size} servers`);
});
bot.on("guildMemberRemove", member => {
console.log(member.user.username + ' left from a Server at ' + now + `Just watch the logs on the server ${guild.name}`)
});
bot.on("message", async message => {
var optionsGreetings = ["Hellouu", "Heyy", "Hi there", "How ya doing?", "LETS GO DUDE"];
var optionsHowAreYou = ["I had a bad day, whats about you, how are you doing?", "Robots have no feelings but whats about you?", "I am pretty good!", "I am doing fine, thanks, and you?", "Im good, how are you?", ];
var responseGreetings = optionsGreetings[Math.floor(Math.random()*optionsGreetings.length)];
var responseHowAreYou = optionsHowAreYou[Math.floor(Math.random()*optionsHowAreYou.length)];
//Hello responses
if(message.content == 'Hello') {
message.channel.send(responseGreetings)
}
if(message.content == 'Hi') {
message.channel.send(responseGreetings)
}
if(message.content == 'Hey') {
message.channel.send(responseGreetings)
}
//How Are you? Responses
if(message.content == 'How are you?') {
message.channel.send(responseHowAreYou)
}
if(message.content == 'ping') {
message.reply(`API Latency is ${Math.round(bot.ping)}ms`)
}
if(message.content == 'why?') {
message.channel.send(`Because!`)
}
if(message.content == 'why') {
message.channel.send(`Because!`)
}
if(message.content == 'Why?') {
message.channel.send(`Because!`)
}
if(message.content == 'Why') {
message.channel.send(`Because!`)
}
});
bot.login('MY_TOKEN')
可能有很多狗屎但是,嘿谁在乎?
我的错误是:ReferneceError:Guild未定义 在 ... 在......
我无法复制的东西,我不想手工打字,希望这有助于你理解我的代码!
答案 0 :(得分:0)
您是在编辑中写的:
bot.on("guildMemberRemove", member => {
console.log(member.user.username + ' left from a Server at ' + now + `Just watch the logs on the server ${guild.name}`)
});
您正在使用guild.name
,但在该函数中,您只在参数中传递member
。
在您发布的第一个代码中,您没有写出来,但在第二个代码中,您尝试将guild.name
替换为member.guild.name