node.js - Discord JS V13 无法向公会所有者发送消息
问题描述
当机器人加入服务器时,我正在尝试向公会所有者发送消息:
client.on('guildCreate', guild => {
const introembed = new MessageEmbed()
.setTitle('Hiya!')
.setColor('RANDOM')
.setDescription(`Thank you for adding me to your server!\nRun \`${prefix}help\` to get my commands!\nThings to know: I am still under developement, and will have a few bugs, feel free to report them with \`${prefix}bugreport\`\nMy GitHub can be found here: https://github.com/*********/*****`)
guild.fetchOwner().then(send({ embeds: [introembed]}).catch(console.error()))
})
这确实有效,从 discord.js v13 开始,我不能再做guild.owner.send()
. 我如何在 v13 中做到这一点?
解决方案
您快到了。您只是为您的.then()
. 我建议使用async
and await
。
试试这个:
client.on("guildCreate", async (guild) => {
const owner = await guild.fetchOwner();
owner.send("This is a test message to the owner of this guild!");
});
或者,如果您想坚持.then()
使用语法,请使用:
client.on("guildCreate", async (guild) => {
guild.fetchOwner().then((owner) =>
owner.send({
embeds: [
new MessageEmbed({
title: "Hiya!",
color: "RANDOM",
description: "This is a test message to the owner of this guild!",
}),
],
})
);
});
推荐阅读
- javascript - 单击jQuery中的按钮时,是否有解决Asp.Net gridview行数据传输到某些特定文本框的解决方案?
- python - 在 exec 节点中传递有效负载值
- php - Symfony 4中用户密码的自定义表单
- java - 我什么时候应该在 INSERT 期间使用 /*+ APPEND */
- javascript - 处理单击并悬停在同一元素上并保持弹出模式打开直到弹出模式悬停在上面
- ios - 如何将镜像添加到 2d Box 角
- reactjs - 在 gatsby.js 网站中嵌入第三方脚本标签
- reactjs - Yarn remove old package (that has security vulnerability)?
- ios - 为 WKWebView 设置约束时崩溃
- html - 为什么网站加载时会出现这个 Button 动画?