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

使用 Discord.js 向頻道發送消息時遇到問題

Having trouble sending a message to a channel with Discord.js(使用 Discord.js 向頻道發送消息時遇到問題)
本文介紹了使用 Discord.js 向頻道發送消息時遇到問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試制作一個機器人,一旦用戶發送特定消息,就會向頻道發送消息.我已經設法讓它在機器人登錄后發送一條消息,但是 client.on() 函數不會做任何事情.如果我做錯了什么,請告訴我,提前謝謝!

I'm trying to make a bot that sends a message to a channel once a user sends a specific message. I've managed to make it send a message once the bot logs in, but the client.on() function won't do anything. Please let me know if I'm doing something wrong, thank you in advance!

const { Client, Intents } = require("discord.js");

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.login("<bot token>");

client.once("ready", () => {
console.log("Ready!");

channel.send("hello world"); //This works

const guild = client.guilds.cache.get("<server id>");
const channel = guild.channels.cache.get("<channel id>");

//This is the issue. Nothing happens when I send "!ping" in the server
client.on("message", message => {
    if (message.content === "!ping") {
        channel.send("pong");
    }
});
});

推薦答案

您需要啟用 GUILD_MESSAGES Intent:

You need to enable the GUILD_MESSAGES intent:

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});

這將使您能夠接收在公會中發送的消息的 MESSAGE_CREATE 事件.

This will enable you to receive the MESSAGE_CREATE event for messages sent in guilds.

可以在 Discord 開發者文檔中找到完整的意圖列表.

A full list of intents can be found on the Discord developer docs.

此外,如果您使用 Discord.js v13,message 事件已被棄用,因為它已重命名為 messageCreate.

Additionally, if you are using Discord.js v13, the message event has been deprecated as it has been renamed to messageCreate.

這篇關于使用 Discord.js 向頻道發送消息時遇到問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
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?)
主站蜘蛛池模板: 亚洲精品久久久久avwww潮水 | 国产精品国产三级国产a | 中文字幕在线视频免费视频 | www.亚洲一区二区三区 | 亚洲国产成人av好男人在线观看 | 国产一区二区三区四区五区3d | 久久精品日产第一区二区三区 | 亚洲欧美在线视频 | 亚洲视频二区 | 日韩三级 | 久久亚洲一区 | 国产精品久久久久久久久久久新郎 | 成人在线看片 | 一区免费看 | 色综合久久88色综合天天 | 精品一区二区久久久久久久网精 | 97影院2| 日日夜夜免费精品 | 东方伊人免费在线观看 | 中文字幕亚洲免费 | 久久一区二区三区四区五区 | 国产一区二区精品在线 | 国产欧美在线视频 | 午夜影院在线 | 五月婷婷在线视频 | 日本三级网站在线观看 | 国产精久久久 | 国产综合一区二区 | 一级毛片在线视频 | 免费av毛片| 国产一区二区三区在线 | 国产视频久久久 | 国产精品久久亚洲 | 精品av久久久久电影 | 亚洲视频在线观看 | 国产日韩一区二区 | 亚洲综合中文字幕在线观看 | 欧美成人一区二免费视频软件 | 亚洲天天 | 久久精品免费看 | 久久久久久99 |