[英]How do I send a DM to a user in discord.js v13
All I'm doing right now is trying to send a dm to myself to see if I can get this working.我现在正在做的就是尝试向自己发送一个 dm,看看我是否可以让它工作。 I've tried:
我试过了:
client.users.cache.get(id).send('hi')
Use UserManager#send()
.使用
UserManager#send()
。 This will create a dm if needed, then send the message如果需要,这将创建一个 dm,然后发送消息
client.users.send(userId, "content")
Please take look at this post , it could resolve your problem.请看这篇文章,它可以解决您的问题。
Basically what it seems to happen is that the get method isn't consistent like fetch.基本上它似乎发生的是get方法不像fetch那样一致。 So prefer to use the fetch method, it will look something like this:
所以更喜欢使用 fetch 方法,它看起来像这样:
const user = await client.users.cache.fetch(id)
user.send('hi')
if you're not in a asynchronous scope you could use the "then" approach:如果您不在异步范围内,则可以使用“then”方法:
client.users.cache.fetch(id)
.then((user) => user.send('hi'))
.catch(e => console.log(e))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.