[英]Discord JS, console.log undefined
我想在其他地方使用msg.content
,
const filter = (m) => m.author.id === message.author.id;
message.channel.send('How many players?');
const msg = await message.channel.awaitMessages(filter, {
max: 1,
time: 10000,
});
console.log(msg.content);
但是當我控制台記錄msg.content
它說它undefined
但是當我控制台記錄所有內容時我可以看到內容(下圖)
它在我使用.then
時有效,但我不想使用它。
在文檔中,您可以看到TextChannel.awaitMessages()
將 Promise 返回到與數組不同的集合。
所以可能的工作是這樣的:
const filter = (m) => m.author.id === message.author.id;
message.channel.send('How many players?');
//it will return a collection even if there's only one message in it
var msg = await message.channel.awaitMessages(filter, {
max: 1,
time: 10000,
});
//convert Collection to array (Array of all messages the filter caught)
msg = Array.from(msg.values())[0];
//that should give the content of the first message the filter caught
console.log(msg.content);
我希望這行得通。 如果沒有,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.