如何回复发送给机器人的任何 DM?
How to reply to any DMs sent to the bot?
我正在尝试让我的机器人回复发送给它的任何 DM。
所以我现在有这个:
client.on('msg', () => {
if (msg.channel.DMChannel) {
msg.reply("You are DMing me now!");
}
});
但不幸的是,它不回复任何 DM。
我尝试用 msg.channel.type == 'dm'
替换 msg.channel.DMChannel
但这没有用。
我也试过用msg.author.send
和msg.channel.send
替换msg.reply
,但都没有用。
如有任何帮助,我们将不胜感激。
谢谢!
您的函数没有收到正确的 'msg' 对象,试试这个:
client.on('message', async message => {
if (message.channel.type == 'dm') {
message.reply("You are DMing me now!");
}
});
编辑:我参考示例代码 here 得出这个结论。也许这个 link 将来会对你有所帮助。祝你好运!
在official documentation I don't see mentioned the event client.on('msg')
only client.on('message')
.
顺便说一句:
client.on('message', msg => {
if (msg.channel.type == "dm") {
msg.author.send("You are DMing me now!");
return;
}
});
刚刚试过了,没有任何问题。
我正在尝试让我的机器人回复发送给它的任何 DM。
所以我现在有这个:
client.on('msg', () => {
if (msg.channel.DMChannel) {
msg.reply("You are DMing me now!");
}
});
但不幸的是,它不回复任何 DM。
我尝试用 msg.channel.type == 'dm'
替换 msg.channel.DMChannel
但这没有用。
我也试过用msg.author.send
和msg.channel.send
替换msg.reply
,但都没有用。
如有任何帮助,我们将不胜感激。
谢谢!
您的函数没有收到正确的 'msg' 对象,试试这个:
client.on('message', async message => {
if (message.channel.type == 'dm') {
message.reply("You are DMing me now!");
}
});
编辑:我参考示例代码 here 得出这个结论。也许这个 link 将来会对你有所帮助。祝你好运!
在official documentation I don't see mentioned the event client.on('msg')
only client.on('message')
.
顺便说一句:
client.on('message', msg => {
if (msg.channel.type == "dm") {
msg.author.send("You are DMing me now!");
return;
}
});
刚刚试过了,没有任何问题。