久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 discord.js 檢測圖像并響應

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
本文介紹了使用 discord.js 檢測圖像并響應的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試為我朋友的 Discord 服務器制作一個惡作劇 Discord 機器人,但機器人不會響應任何東西;甚至 elseif 函數也沒有通過.如果有人知道我的代碼為什么不起作用,請指定它.

I'm trying to make a prank Discord bot for my friend's Discord server, but the bot won't respond to anything; not even the elseif function passes. If anyone know why my code isn't working can you please specify it.

注意:如果您需要參考,客戶端變量是 Discord.Client.

NOTE: Client variable is Discord.Client if you needed a reference.

client.on("message", message => {
  if (message.channel.id != 425328056777834506) return;
  if (Math.floor(Math.random() * Math.floor(4))== 3 && message.embeds.length > 0) {
    message.channel.send("https://cdn.discordapp.com/attachments/330441704073330688/453693702687162369/yeet.png");
  } else if (message.embeds.length < 0) {
    message.channel.send("send me photos of your win >.>");
  }
})

推薦答案

消息有一個 attachments 屬性,您可以使用它來獲取消息的附件集合(如果有)

The Message have a attachments property which you can use to get a collection of attached file(s) to a message (if any)

您可以先執行 if (message.attachments.size > 0) 來檢查任何附加對象.
之后,您可以遍歷集合并檢查附件 URL 是否以 pngjpeg 結尾.

You can do a if (message.attachments.size > 0) to check for any attached objects first.
Afterwards, you can loop through the collection and check if the attached file URL ends with a png or jpeg.

if (message.attachments.size > 0) {
    if (message.attachments.every(attachIsImage)){
        //something
    }
}
        
...
        
function attachIsImage(msgAttach) {
    var url = msgAttach.url;
    //True if this url is a png image.
    return url.indexOf("png", url.length - "png".length /*or 3*/) !== -1;
}

編輯

因為你的機器人沒有響應任何東西.確保您在 message.channel.id != 425328056777834506 語句中具有相同 ID 的頻道中測試機器人.
(或者您可以先注釋掉 if 語句,然后在您的機器人功能齊全時添加.)

For your bot not responding to anything. Make sure that you are testing the bot in the channel that has the same ID in the message.channel.id != 425328056777834506 statement.
(Or you can comment out that if statement first, then add that in when your bot is fully functional.)

此外,client.on("message", message => {... 也會在您的機器人發送消息時被調用.您可以執行 if (message.author.id == <YourBotID>) {return;} 讓機器人忽略它自己的消息.
或者,如果您希望它忽略其他機器人發送的消息,您可以執行 if (message.author.bot) {return;}.

Also, client.on("message", message => {... gets called when your bot sends a message too. You can do if (message.author.id == <YourBotID>) {return;} to let the bot ignore it's own messages.
Or you can do if (message.author.bot) {return;} if you want it to ignore messages sent by other bots.

這篇關于使用 discord.js 檢測圖像并響應的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
DeprecationWarning: Collection#find: pass a function instead(DeprecationWarning: Collection#find: 傳遞一個函數)
主站蜘蛛池模板: 一级特黄毛片 | 国产精品三级在线 | 国产精品福利在线 | 免费的黄色小视频 | 天天操天 | 日韩精品视频在线播放 | 麻豆精品一区 | 国产传媒视频在线观看 | 天堂网久久| 日韩成人在线播放 | 成年人在线观看 | 成人午夜在线视频 | 黄色免费大片 | www.国产在线 | 欧美a一级 | 天海翼在线视频 | 黄色av大片| 99精品色 | 男人亚洲天堂 | 中文字幕免费av | 成人午夜视频在线观看 | 成人高潮片免费 | 精品成人在线 | 亚洲精品一区中文字幕乱码 | 国产女人高潮视频 | 久久免费精品 | 午夜精品国产精品大乳美女 | 天天操操操操 | 四虎影视在线 | 在线日韩 | 黄色大片视频 | 国产欧美日韩 | 第一福利丝瓜av导航 | 日韩欧美国产成人 | 九九综合网 | 久久午夜影院 | 日本成人一区二区三区 | 亚洲久久久 | avtt久久 | 午夜影院免费 | 国产精品美女毛片真酒店 |