在 discord.js 和 bot.on('guildMemberAdd', async newMember => 中创建欢迎消息正在创建错误
Posted
技术标签:
【中文标题】在 discord.js 和 bot.on(\'guildMemberAdd\', async newMember => 中创建欢迎消息正在创建错误【英文标题】:Creating a welcome message in discord.js and bot.on('guildMemberAdd', async newMember => is creating errors在 discord.js 和 bot.on('guildMemberAdd', async newMember => 中创建欢迎消息正在创建错误 【发布时间】:2021-10-03 15:41:21 【问题描述】:我正在尝试为 discord 机器人创建欢迎消息,我按照指南等所说的做了,但在谈论 bot.on('guildMemberAdd', async newMember =>
部分时出现错误“机器人未定义”,这是使用 discord.js V12
我的完整代码是:
const MessageEmbed = require("discord.js");
module.exports.run = (client, message, args) =>
message.delete()
// This is the needed event to use the welcome!
bot.on('guildMemberAdd', async newMember =>
// IMPORTANT NOTE: Make Sure To Use async and rename bot to client or whatever name you have for your bot events!
const welcomeChannel = newMember.guild.channels.cache.find(channel => channel.name === 'imperial')
welcomeChannel.send('Welcome User')
)
;```
【问题讨论】:
您的bot
被命名为client
...
啊,非常感谢,这是我的愚蠢错误,但至少这是一个简单的修复:)
【参考方案1】:
您已将 Bot 定义为客户端。所以你必须这样做client.on
const MessageEmbed = require("discord.js");
module.exports.run = (client, message, args) =>
message.delete()
// This is the needed event to use the welcome!
client.on('guildMemberAdd', async newMember =>
// IMPORTANT NOTE: Make Sure To Use async and rename bot to client or whatever name you have for your bot events!
const welcomeChannel = newMember.guild.channels.cache.find(channel => channel.name === 'imperial')
welcomeChannel.send('Welcome User')
)
;```
【讨论】:
以上是关于在 discord.js 和 bot.on('guildMemberAdd', async newMember => 中创建欢迎消息正在创建错误的主要内容,如果未能解决你的问题,请参考以下文章
类型错误:不是 NODE JS DIScord Bot 中的函数 [关闭]
Discord bot Javascript 声明或预期声明