問題描述
所以過去幾天我一直非常沮喪,因為我無法在網上找到一個資源來正確記錄在用 javascript 編寫不和諧機器人時如何找到表情符號.我一直在參考本指南,其有關表情符號的文檔似乎是錯誤的或過時的:
So I have been utterly frustrated these past few days because I have not been able to find a single resource online which properly documents how to find emojis when writing a discord bot in javascript. I have been referring to this guide whose documentation about emojis seems to be either wrong, or outdated:
https://anidiots.guide/coding-guides/using-emojis
我需要的很簡單;只是能夠使用 .find()
函數引用表情符號并將其存儲在變量中.這是我當前的代碼:
What I need is simple; to just be able to reference an emoji using the .find()
function and store it in a variable. Here is my current code:
const Discord = require("discord.js");
const config = require("./config.json");
const fs = require("fs");
const client = new Discord.Client();
const guild = new Discord.Guild();
const bean = client.emojis.find("name", "bean");
client.on("message", (message) => {
if (bean) {
if (!message.content.startsWith("@")){
if (message.channel.name == "bean" || message.channel.id == "478206289961418756") {
if (message.content.startsWith("<:bean:" + bean.id + ">")) {
message.react(bean.id);
}
}
}
}
else {
console.error("Error: Unable to find bean emoji");
}
});
附言整個 bean 只是一個測試
但是每次我運行這段代碼時,它都會返回這個錯誤并死掉:
But every time I run this code it just returns this error and dies:
(node:3084) DeprecationWarning: Collection#find: 傳遞一個函數
有什么我錯過的嗎?我好難過……
Is there anything I missed? I am so stumped...
推薦答案
我沒用過 discord.js
所以我可能完全錯了
I never used discord.js
so I may be completely wrong
從警告中我會說你需要做類似的事情
from the warning I'd say you need to do something like
client.emojis.find(emoji => emoji.name === "bean")
加上查看 Discord.js Doc
這似乎是要走的路.但是文檔從來沒有說過 client.emojis.find("name", "bean")
是錯誤的
這篇關于如何在 Discord.js 中按名稱查找表情符號的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!