[英]Working on a Discord bot with discord.js, tempmute won't work
[英]This discord bot that greets people when they join my server won't work?
我正在嘗試向使用此機器人加入我的 discord 服務器的任何人發出歡迎信息,但是當有人加入時沒有任何反應。 我收到一個錯誤:
ReferenceError: 通道名稱未在 C:\Users\Vir\Desktop\DiscBot\index.js:13:71 在 Map.find (C:\Users\Vir\Desktop\DiscBot\node_modules\discord. \Collection.js:506:11) 在客戶端。 (C:\Users\Vir\Desktop\DiscBot\index.js:13:43) 在 Client.emit (events.js:223:5) 在 Guild._addMember (C:\Users\Vir\Desktop\DiscBot\node_modules \discord.js\src\structures\Guild.js:1298:19) 在 GuildMemberAddHandler.handle (C:\Users\Vir\Desktop\DiscBot\node_modules\discord.js\src\client\websocket\packets\handlers\GuildMemberAdd .js:12:13) 在 WebSocketPacketManager.handle (C:\Users\Vir\Desktop\DiscBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65) 在 WebSocketConnection.onPacket ( C:\Users\Vir\Desktop\DiscBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35) 在 WebSocketConnection.onMessage (C:\Users\Vir\Desktop\DiscBot\node_modules\discord .js\src\client\websocket\WebSocketConnection.js:296:17) 在 WebSocket.onMessage (C:\Users\Vir\Desktop\DiscBot\node_modules\ws\lib\event-target.js:120:16) PS C:\Users\Vir\Desktop\DiscBot>
但我不知道這意味着什么。 我已經嘗試搜索它並沒有發現任何東西。
代碼是
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = "NzEzMTcwNjc4NjYwMjAyNTA2.XscOxQ.0YxwpbBEITN0DIwGFwYIdRxCOu0";
const PREFIX = ";";
bot.on('ready', () =>{
console.log('This bot is online!');
})
bot.on('guildMemberAdd', member =>{
const channel = member.guild.channels.find(channel => channelname === "welcome");
if(!channel) return;
channel.send('Welcome, ${member}, make sure to read the rules and verfiy.')
});
bot.on('message', message=>{
let args = message.content.substring(PREFIX.length).split(" ")
switch(args[0]){
case 'Version':
message.reply('Version 1.0.0');
break;
case 'Commands':
message.reply(';Version ;Commands');
break;
}
})
bot.login(token);
這是我用於此的代碼
client.on("guildMemberAdd", (member) => {
const channel = member.guild.channels.cache.get('CHANNEL_ID');
channel.send(`**Hey ${member.user}, welcome to the server!\nMake sure to read the rules in <#CHANNEL_ID>**`);
});
他們已經改變了它,所以你現在需要使用cache
。 所以在這種情況下:
bot.on('guildMemberAdd', member =>{
const channel = member.guild.channels.cache.find(channel => channel.name === "welcome");
if(!channel) return;
channel.send('Welcome, ${member}, make sure to read the rules and verfiy.')
});
希望這可以幫助!
該錯誤表明未定義channelname
名稱。 我相信您應該改用channel.name
,只是一個簡單的錯字。
根據 OP 的評論,我檢查了文檔,您必須訪問cache
屬性以獲取頻道列表,如下所示:
bot.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(channel => channel.name === "welcome");
if(!channel) {
return;
}
channel.send(`Welcome, ${member}, make sure to read the rules and verfiy.`)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.