为什么我在获取消息时出错?
Why am I getting an error fetching messages?
调用脚本时出错。你能寻求帮助吗?
下面我粘贴了代码和错误。
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = chn.fetchMessage('717369584801546273');
msg.edit(embedit);
TypeError: msg.edit is not a function
这是 v11 吗?
尽管获取某些东西是异步的,因此您需要等待 msg 解析。
https://discord.js.org/#/docs/main/11.1.0/class/TextChannel?scrollTo=fetchMessage
以下是您的操作方法:
第一个是使用 await ,它需要在异步函数中
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = await chn.fetchMessage('717369584801546273');
msg.edit(embedit);
第二个是.then
let chn = client.channels.find(channel => channel.id === '717019301357420554');
chn.fetchMessage('717369584801546273').then(msg => msg.edit(embedit));
如果要保存在变量中
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg;
chn.fetchMessage('717369584801546273').then(m => msg = m);
//note you will have to wait for the promise to resolve to use
//the variable msg correctly
//any code beyond this isn't guranteed to have access to
顺便说一句,这些是一些错误的变量名,您不应该使用 chn
之类的缩写,而应使用 channel
和 embedit
=> embEdit
。但取决于你
调用脚本时出错。你能寻求帮助吗?
下面我粘贴了代码和错误。
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = chn.fetchMessage('717369584801546273');
msg.edit(embedit);
TypeError: msg.edit is not a function
这是 v11 吗?
尽管获取某些东西是异步的,因此您需要等待 msg 解析。
https://discord.js.org/#/docs/main/11.1.0/class/TextChannel?scrollTo=fetchMessage
以下是您的操作方法:
第一个是使用 await ,它需要在异步函数中
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg = await chn.fetchMessage('717369584801546273');
msg.edit(embedit);
第二个是.then
let chn = client.channels.find(channel => channel.id === '717019301357420554');
chn.fetchMessage('717369584801546273').then(msg => msg.edit(embedit));
如果要保存在变量中
let chn = client.channels.find(channel => channel.id === '717019301357420554');
let msg;
chn.fetchMessage('717369584801546273').then(m => msg = m);
//note you will have to wait for the promise to resolve to use
//the variable msg correctly
//any code beyond this isn't guranteed to have access to
顺便说一句,这些是一些错误的变量名,您不应该使用 chn
之类的缩写,而应使用 channel
和 embedit
=> embEdit
。但取决于你