I tried for a moment to make a command to kick a member, but after testing in mons discord, no message appears, and the member is not kick.
So this is for a bot discord with Node.js. I tried to remake commands via sites, and via videos (for the kick command), the editor does not give me any error, but the bot does not respond to the command in question
client.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'kick' :
if(!args[1]) message.channel.send('Vous devez spécifier la personne.')
const user = message.mentions.users.first();
if(user){
const member = member.guild.member(user);
if(member){
member.kick('Vous avez été expulsé du serveur !').then(() =>{
message.reply('Le joueur suivant a été expulsé : ${user.tag}');
}).catch(err =>{
message.reply('I was unable to kick the member')
console.log(err);
});
} else
message.reply("Le membre n'est pas dans la guilde.")
}
}
})
I would therefore, possible, know why this command does not work. Even though I think I should answer your questions. Thanks in advance for all the help !
答案 0 :(得分:0)
您可以尝试使用命令处理程序,也可以使用此guide 然后在该文件夹中为命令创建一个文件夹,您可以创建kick.js,该文件将用于kick命令,然后执行
let kUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!kUser) return message.channel.send("Please mention a user to kick!")
let kReason = args.join(" ").slice(22);
if(!kReason) return message.channel.send ("Please specify some reasons for the kick")
message.guild.member(kUser).kick(kReason);
message.channel.send(`${kUser} has been kicked from the server`);
请记住也要检查权限,这样您就可以确定他们在踢踢成员之前是否具有权限,也可以决定在用户单击这样的机器人之后将踢踢记录在机器人向其发送消息的通道中
// this will look for logchannel so if you don't have that channel you can create or let logchannel = message.guild.channels.find(c => c.name === "logchannel");
logchannel.send(`${kUser} has been kicked from the server`);
答案 1 :(得分:0)
好的,我发现了我的问题,而我的问题是:我没有激活OAuth2。现在,我要执行命令,并且收到以下消息:
client.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'kick' :
if(!args[1]) message.channel.send('Vous devez spécifier la personne.')
const user = message.mentions.users.first();
if(user){
const member = member.guild.member(user);
if(member){
member.kick('Vous avez été expulsé du serveur !').then(() =>{
message.reply('Le joueur suivant a été expulsé : ${user.tag}');
}).catch(err =>{
message.reply('I was unable to kick the member')
console.log(err);
});
} else
message.reply("Le membre n'est pas dans la guilde.")
}
}
})
和控制台日志中写道:
ReferenceError: PREFIX is not defined
at Client.<anonymous> (C:\Users\Thomas\Desktop\Nolosha Bot\index.js:44:40)
←[在Client.emit处为90m(events.js:205:15)←[39m 位于MessageCreateHandler.handle(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ packets \ handlers \ MessageCreate.js:9:34) 在WebSocketPacketManager.handle(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ packets \ WebSocketPacketManager.js:105:65) 在WebSocketConnection.onPacket上(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ WebSocketConnection.js:333:35) 在WebSocketConnection.onMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ WebSocketConnection.js:296:17)) 在WebSocket.onMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mws←[24m \ lib \ event-target.js:120:16) ←[在WebSocket.emit处为90m(events.js:200:13)←[39m 在Receiver.receiverOnMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mws←[24m \ lib \ websocket.js:789:20) ←[在Receiver.emit处为90m(events.js:200:13)←[39m
C:\ Users \ Thomas \ Desktop \ Nolosha Bot>节点index.js 成功 C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ index.js:44 let args = message.content.substring(PREFIX.length).split(“”); ^
ReferenceError:未定义PREFIX 在客户处。 (C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ index.js:44:40) ←[在Client.emit处为90m(events.js:205:15)←[39m 位于MessageCreateHandler.handle(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ packets \ handlers \ MessageCreate.js:9:34) 在WebSocketPacketManager.handle(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ packets \ WebSocketPacketManager.js:105:65) 在WebSocketConnection.onPacket上(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ WebSocketConnection.js:333:35) 在WebSocketConnection.onMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mdiscord.js←[24m \ src \ client \ websocket \ WebSocketConnection.js:296:17)) 在WebSocket.onMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mws←[24m \ lib \ event-target.js:120:16) ←[在WebSocket.emit处为90m(events.js:200:13)←[39m 在Receiver.receiverOnMessage(C:\ Users \ Thomas \ Desktop \ Nolosha Bot \ node_modules \←[4mws←[24m \ lib \ websocket.js:789:20) ←[在Receiver.emit处为90m(events.js:200:13)←[39m
请帮助我