我有點堅持這部分代碼。我目前正在為學校專案和個人用途撰寫一個不和諧的機器人。discord 機器人的主要目的是發送嵌入和隨意的命令,其中有人說“晚安”,機器人會回復晚安。對于代碼的晚安部分,我寫得非常正確,但是如何通過標記persons discord標簽來讓它回應?比如我現在的代碼不是我else if (message.content === 'goodnight'){ message.channel.send('Goodnight!');如何讓它說“晚安@discordtag”
其次,代碼的嵌入部分是我最苦惱的部分。我非常關注https://discordjs.guide上的指南以及一些 youtube 視頻,但我似乎無法找到答案。我收到錯誤“channel.send({ embeds: [exampleEmbed] }); ^
TypeError: Cannot read properties of undefined (reading 'send')" 我的示例嵌入代碼是
const exampleEmbed = new MessageEmbed()
.setColor('#5104DB')
.setTitle("Boombap's Cookout Rules")
.setAuthor({ name: 'Rules', iconURL: 'https://gridfiti.com/wp-content/uploads/2021/04/Gridfiti_Blog_AnimeCars_NissanSilviaS13.jpg'})
.addFields(
{ name: 'Rule 1', value: 'No racist, sexist or any type of hate speech towards other members.'},
{ name: 'Rule 2', value: 'No scamming.'},
{ name: 'Rule 3', value: 'No discussions of anything illegal, if you think it might be just do not mention it in the discord.'},
{ name: 'Rule 4', value: 'No advertisements of other services.'}
)
channel.send({ embeds: [exampleEmbed] });```
Any help and tips and tricks will help!
uj5u.com熱心網友回復:
要回答問題的第一部分,您可以通過Goodnight ${message.author}or提及用戶Goodnight <@${message.author.id}>- 兩者都將回傳相同的值(不和諧提及)。
channel是未定義的,所以這意味著沒有send()錯誤提示的屬性。您可以獲取/快取通道以發送到特定通道,例如
const channel = client.channels.cache.get('ID');
或者使用- DJS Docschannel上的屬性:Message: channelmessagemessage.channel.send()
uj5u.com熱心網友回復:
什么是渠道定義?嘗試將頻道替換為message.channel
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408578.html
標籤:
