Discord JS,console.log 未定义
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
但我不想使用它时它有效。
In the docs you can see that TextChannel.awaitMessages()
returns a Promise to a Collection 这与数组不同。
那么可行的是:
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);
我希望这能奏效。如果不是请告诉我。
我想在其他地方使用 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
但我不想使用它时它有效。
In the docs you can see that TextChannel.awaitMessages()
returns a Promise to a Collection 这与数组不同。
那么可行的是:
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);
我希望这能奏效。如果不是请告诉我。