0

所以我希望机器人@他正在与之交谈的用户,因为 ${member}(我在 youtube 上看到)不起作用,所以我想问我要写什么,以便他写“你好 @(用户名) ...”请记住,他是作为 dm 写的。

const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();

client.on('ready', () => {
    console.log('This Bot is online!');
})

client.login(token);

client.on('guildMemberAdd', member => {
    member.send('Hello ${member}, welcome to the PotatoHost Server!');
});
4

2 回答 2

1

问题不在于成员,而在于 client.login(),如果代码应该总是在最后!

我希望这能帮到您。祝你有美好的一天!

编辑:另外,有些成员已经锁定了 dm,所以你应该使用 try-catch 功能,如果你遇到错误,请在聊天中发送欢迎消息。

try-catch 函数是这样工作的:

try{
member.send("message here")
}catch(error){
member.guild.channels.get("here the Id of the channel you want to send the welcome message in").send("message here")
}

如果您不喜欢在服务器的频道中发送消息的想法,请改为:

console.log(error)
于 2020-04-14T12:33:29.923 回答
1

我开始时遇到了同样的问题,这应该可以帮助您解决问题:

client.on("guildMemberAdd", async member => {
const dmErr = false;
try {
await member.send()
} catch (error) {
dmErr = true;
} if (dmErr === true) {
member.guild.channels.get("Id of the channel here").send()
}
}); 
于 2020-04-14T18:23:32.950 回答