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

使用 discord.js 檢測圖像并響應(yīng)

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

問題描述

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

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 >.>");
  }
})

推薦答案

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

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

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

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;
}

編輯

因?yàn)槟愕臋C(jī)器人沒有響應(yīng)任何東西.確保您在 message.channel.id != 425328056777834506 語句中具有相同 ID 的頻道中測試機(jī)器人.
(或者您可以先注釋掉 if 語句,然后在您的機(jī)器人功能齊全時(shí)添加.)

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 => {... 也會(huì)在您的機(jī)器人發(fā)送消息時(shí)被調(diào)用.您可以執(zhí)行 if (message.author.id == <YourBotID>) {return;} 讓機(jī)器人忽略它自己的消息.
或者,如果您希望它忽略其他機(jī)器人發(fā)送的消息,您可以執(zhí)行 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.

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

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

相關(guān)文檔推薦

Check if user ID exists in Discord server(檢查 Discord 服務(wù)器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會(huì)成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創(chuàng)建我的第一個(gè)機(jī)器人,但總是錯(cuò)誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機(jī)器人編寫事件/命令處理程序?)
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: 傳遞一個(gè)函數(shù))
主站蜘蛛池模板: 亚洲综合无码一区二区 | 看一级黄色毛片 | 欧美性猛片aaaaaaa做受 | 免费视频一区二区 | 99re视频在线| 99九色| 国产欧美精品一区二区色综合朱莉 | 久久爆操 | 欧美性乱 | 午夜影院免费体验区 | 国产精品久久久久久久岛一牛影视 | 久久久久久久久淑女av国产精品 | 国产激情自拍视频 | 久久久久一区 | 99国产精品一区二区三区 | 日韩一区二区福利 | 国产av毛片 | www.4567| 亚洲一区二区三区四区五区中文 | 日韩精品在线一区 | 精品日韩一区 | 精品一区二区久久久久久久网站 | 欧美精品乱码99久久影院 | 国产精品一二三区 | 国产精品色综合 | 国产精品一区二区无线 | 国产一区高清 | 国产精品久久久久久亚洲调教 | 亚洲图片一区二区三区 | 91久久国产 | 国产精品一区二区三区在线播放 | 欧美国产视频 | 99在线精品视频 | 爱爱免费视频 | 免费一级欧美在线观看视频 | 久久国产激情视频 | 久久久精品视频一区二区三区 | 中文字幕免费视频 | 欧美一区二区三区在线观看 | www.夜夜骑.com | h视频在线播放 |