node.js - 如何使用消息 ID 在 Discord.js 中编辑消息
问题描述
有在 DiscordJS 上编辑消息的方法
解决方案
为此,我们只需要将它传递给函数,即客户端变量。
exports.myNewFunction = async function myNewTestFunction(client)
首先,为了使用 Discord.JS API 编辑消息,我们需要找到服务器的 GuildID。
const guild = client.guilds.cache.get(`Your Guild ID`);
现在,我们需要找到消息所在的频道。为此,我们将使用频道 ID
const channel = guild.channels.cache.find(c => c.id === `Your message Channel` && c.type === 'text');
最后,让我们进入消息的编辑部分。为此,我们只需要提供您要编辑的消息的 ID。
channel.messages.fetch(`Your Message ID`).then(message => {
message.edit("New message Text");
}).catch(err => {
console.error(err);
});
推荐阅读
- javascript - 如何将 firebase firestore 与我的本地 firebase 模拟器套件连接?
- javascript - NodeJS:等待直到数组被填充
- typescript - 如何在 Jest 中使用全局变量并通过 cmd 传递它
- mysql - 续集 MySQL 查询
- c# - 函数抽象类,学习OOP
- c# - c#如果我在SqlCommand中传递一个参数,像sqlcommand中的运算符不起作用
- javascript - NodeJS:测试IP是否可达的问题
- dbt - 如何在代理后面运行 dbt deps?
- javascript - 在 Safari 中将输入插入符号位置设置为模糊而不重新聚焦输入
- pyspark - Pyspark load-csv 不显示新文件的真实模式(仅“推断”模式)