正在尝试设置新的 welcome.js
Trying to setup a new welcome.js
const Discord = require('discord.js')
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
const config = require('./botconfig.json')
const prefix = '...';
const welcome = require("./welcome");
const Welcome = require("discord-welcome");
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
],
});
bot.on('ready', async () => {
console.log(`${bot.user.username} is online and in ${bot.guilds.cache.size} server!`)
})
// START OF WELCOME BOT
bot.on('guildMemberAdd', async member => {
client.channels.cache.get('ChannelHere')
let embed = new Discord.MessageEmbed()
.setTitle('TESTING EMBED')
.setDescription('TITLE LAUNCHED...')
.setColor("#ffd8e3")
channel.send(`please welcome ${member} to the server!`, embed)
//client.channels.get("775086826154229840").send(`please welcome ${member} to the server!`, embed)
//msg.channel.send(`please welcome ${member} to the server!`, embed)
});
// END OF WELCOME BOT
bot.login(config.token)
每当用户加入时,它都会失败。它在上一个服务器上工作但现在不工作?
任何帮助或表明有问题的迹象将不胜感激。
我是新手,很抱歉,如果不好
所以这里有一些错误。首先,您定义了 2 个“客户”
// first client
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
// second client
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
],
});
那么你的代码如下
bot.on(‘guildMemberAdd’, async member => {
// above line states that the first client will do something when a member joins
client.channels.cache.get('ChannelHere')
//above line states that the second client will retrieve the channel
…
channel.send(`please welcome ${member} to the server!`, embed)
//above line has the first client doing something (sending a message) however the first client didn’t retrieve the channel so channel.anything won’t work.
client.channels.cache.get("775086826154229840").send(`please welcome ${member} to the server!`, embed)
//this line would technically work except client isn’t logged in, bot is and you needed the .cache part
msg.channel.send(`please welcome ${member} to the server!`, embed)
// msg is not defined probably just need to delete msg
});
}
试试这个,它应该有效
const Discord = require('discord.js')
// if using discord v12 pick only one bot
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
// if using discord v13 pick only one bot
const bot = new Discord.Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES]
})
const config = require('./botconfig.json')
const prefix = '...';
const welcome = require("./welcome");
const Welcome = require("discord-welcome");
bot.on('ready', async () => {
console.log(`${bot.user.username} is online and in ${bot.guilds.cache.size} server!`)
})
// START OF WELCOME BOT
bot.on('guildMemberAdd', async member => {
const channel = bot.channels.cache.get('ChannelHere')
let embed = new Discord.MessageEmbed()
.setTitle('TESTING EMBED')
.setDescription('TITLE LAUNCHED...')
.setColor("#ffd8e3")
// if using discord v12
channel.send(`please welcome ${member} to the server!`, embed)
// if using discord v13
channel.send({
content: `please welcome ${member} to the server!`,
embeds: [embed]
})
});
// END OF WELCOME BOT
bot.login(config.token)
const Discord = require('discord.js')
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
const config = require('./botconfig.json')
const prefix = '...';
const welcome = require("./welcome");
const Welcome = require("discord-welcome");
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
],
});
bot.on('ready', async () => {
console.log(`${bot.user.username} is online and in ${bot.guilds.cache.size} server!`)
})
// START OF WELCOME BOT
bot.on('guildMemberAdd', async member => {
client.channels.cache.get('ChannelHere')
let embed = new Discord.MessageEmbed()
.setTitle('TESTING EMBED')
.setDescription('TITLE LAUNCHED...')
.setColor("#ffd8e3")
channel.send(`please welcome ${member} to the server!`, embed)
//client.channels.get("775086826154229840").send(`please welcome ${member} to the server!`, embed)
//msg.channel.send(`please welcome ${member} to the server!`, embed)
});
// END OF WELCOME BOT
bot.login(config.token)
每当用户加入时,它都会失败。它在上一个服务器上工作但现在不工作? 任何帮助或表明有问题的迹象将不胜感激。 我是新手,很抱歉,如果不好
所以这里有一些错误。首先,您定义了 2 个“客户”
// first client
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
// second client
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
],
});
那么你的代码如下
bot.on(‘guildMemberAdd’, async member => {
// above line states that the first client will do something when a member joins
client.channels.cache.get('ChannelHere')
//above line states that the second client will retrieve the channel
…
channel.send(`please welcome ${member} to the server!`, embed)
//above line has the first client doing something (sending a message) however the first client didn’t retrieve the channel so channel.anything won’t work.
client.channels.cache.get("775086826154229840").send(`please welcome ${member} to the server!`, embed)
//this line would technically work except client isn’t logged in, bot is and you needed the .cache part
msg.channel.send(`please welcome ${member} to the server!`, embed)
// msg is not defined probably just need to delete msg
});
}
试试这个,它应该有效
const Discord = require('discord.js')
// if using discord v12 pick only one bot
const bot = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"]})
// if using discord v13 pick only one bot
const bot = new Discord.Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES]
})
const config = require('./botconfig.json')
const prefix = '...';
const welcome = require("./welcome");
const Welcome = require("discord-welcome");
bot.on('ready', async () => {
console.log(`${bot.user.username} is online and in ${bot.guilds.cache.size} server!`)
})
// START OF WELCOME BOT
bot.on('guildMemberAdd', async member => {
const channel = bot.channels.cache.get('ChannelHere')
let embed = new Discord.MessageEmbed()
.setTitle('TESTING EMBED')
.setDescription('TITLE LAUNCHED...')
.setColor("#ffd8e3")
// if using discord v12
channel.send(`please welcome ${member} to the server!`, embed)
// if using discord v13
channel.send({
content: `please welcome ${member} to the server!`,
embeds: [embed]
})
});
// END OF WELCOME BOT
bot.login(config.token)