我在执行此代码时收到错误:
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.();
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')
里面可能有很多,但是,嘿,谁在乎呢?
我的错误,ocurs 是:referneceError:公会不是定义在...在...
吨的东西,我不能复制,我不想手动键入它,希望这可以帮助你理解我的 code!

您在编辑中写道:
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
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(18条)