2 回答

TA貢獻1860條經驗 獲得超9個贊
在您嘗試向其發送消息時,該頻道不存在。
您正在使用.then(),.catch()因此您必須對承諾有一定的了解。請記住,promise 表示的操作不會在任何地方完成,除了在 promise 回調內部(或在您使用 之后await)。
基本上你是這樣寫的:
//send a request to Discord to make a channel
message.guild.channels.create(name, {...}).catch(console.error);
...
//immediately, without waiting for Discord to make the channel, send a message to it
message.guild.channels.cache.find(r => r.name === name).send(Embed);
您發送消息的代碼取決于已經創建的頻道。因此,它需要在承諾的.then()回調中。channels.create(...)這還有一個額外的好處,即 promise 將實際解析通道對象,因此您可以調用.send()它而不需要搜索緩存。
message.guild.channels.create(name, {...}).then(chan => {
//make embed
chan.send(Embed);
}).catch(console.error);
您將需要類似地附加 a.then()到.send()呼叫以對剛剛發送的消息做出反應。因為您需要等待 Discord 真正發出消息,然后才能對其做出反應。

TA貢獻1806條經驗 獲得超8個贊
如果未定義,則意味著您需要的具有該名稱的頻道不存在。我不知道在你的情況下你會如何處理這個,但這是一個選擇:
const Embed = new Discord.MessageEmbed()
.setTitle('ISLAND INFO');
const channel = message.guild.channels.cache.find(r => r.name === name);
if (!channel) message.channel.send("Your channel does not exist!");
else {
channel.send(embed)
}
按用戶名存儲數據時要注意的另一件事是用戶名可以更改。我建議你用用戶 ID 命名你的頻道,因為這些永遠不會改變
添加回答
舉報