久久久久久久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ù))
主站蜘蛛池模板: 日本粉嫩一区二区三区视频 | 国产一区二区三区在线 | 日韩午夜网站 | 日本一二区视频 | 国产精品毛片在线 | 国产精品123区 | 久久伊人影院 | 欧美精品91 | 欧美性大战久久久久久久蜜臀 | 欧美一区二区三区的 | 日韩欧美在线一区 | 中文字幕精品一区 | 一级毛片网 | 日韩成人 | 国产精品一区二区电影 | 久久久国产一区二区三区四区小说 | 最新国产精品精品视频 | 伦理片97| 97免费在线观看视频 | 蜜桃视频在线观看免费视频网站www | 国产女人精品视频 | 暖暖成人免费视频 | 久久亚洲欧美日韩精品专区 | 久久久久久久久久久久久久av | 99久热在线精品视频观看 | 日本成人中文字幕在线观看 | 可以免费看的毛片 | 久久久久久九九九九九九 | 懂色中文一区二区三区在线视频 | 久久四虎 | 美国黄色毛片 | www.天天干.com| 日本三级电影在线免费观看 | 日韩中文字幕在线免费 | 国产精品不卡 | 国产福利在线视频 | 日本a在线| 久久成人免费视频 | 夜夜夜久久久 | 午夜男人天堂 | 色婷婷综合久久久久中文一区二区 |