简体   繁体   English

如何让我的 Discord 机器人发送欢迎消息?

[英]How do I get my Discord bot to send a welcome message?

I've watched numerous videos, and followed examples online, and still can't get my discord bot to simply send a message upon a member joining.我看过很多视频,并在网上关注示例,但仍然无法让我的 discord 机器人在会员加入时简单地发送消息。 Maybe I'm missing out on an important update?也许我错过了一个重要的更新?

//require the necessary discord.js classes
const { Client, Intents } = require("discord.js");
const { token } = require("./config.json");

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

//when the client is ready, run this code (only once)
client.on('ready', () => {
    console.log("Online");
});

//sends user a welcome message upon joining
client.on('guildMemberAdd', member => {
    const channel = member.guild.channels.cache.get('921490782958014576');    
    channel.send("Welcome to the server!!")
});

client.login(token);

I get nothing.我什么都得不到。 Nada.纳达。 I've tried several different pieces of code.我已经尝试了几段不同的代码。 I've TRIPLE checked the permissions.我已经三重检查了权限。 This is very frustrating.这非常令人沮丧。 I've tried unadding and readding the bot to the server.我已经尝试将机器人取消添加并将其读取到服务器。 I checked up on the discord.js documentation and nothing seems to be wrong with my code.我检查了 discord.js 文档,我的代码似乎没有任何问题。 To me it seems as if the guildMemberAdd isn't emitting anything.对我来说,好像 guildMemberAdd 没有发出任何东西。 I'm using notepad++ to edit my code.我正在使用记事本++ 来编辑我的代码。 I feel I could be using something better for debugging purposes possibly.我觉得我可能会使用更好的东西来进行调试。

The issue may be due to missing intents.该问题可能是由于缺少意图。 Try adding the GUILD_MEMBERS intent to your list of intents like so.尝试像这样将GUILD_MEMBERS意图添加到您的意图列表中。

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

discord.js docs: https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS discord.js 文档: https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS

Developer docs: https://discord.com/developers/docs/topics/gateway#gateway-intents开发者文档: https://discord.com/developers/docs/topics/gateway#gateway-intents

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的 discord 机器人加入服务器时,如何发布欢迎消息 - How do I post a welcome message when my discord bot joins a server 当特定用户玩特定游戏时,如何让我的不和谐机器人发送消息? - How do I make my discord bot send a message when a specific user plays a specific game? 如何让 discord 机器人在加入时发送消息 - How do I make a discord bot send a message upon joining 我如何让机器人在不带“\\_poll”的情况下使用 discord.js 发送轮询消息的 adv poll 命令 - How do I get a bot to send the message of the poll without the '\_poll' for an adv poll command with discord.js 如何制作 discord 机器人欢迎命令和离开命令 - How do I make a discord bot welcome command and leave command 如何让我的不和谐机器人自动回复消息? - How do I make my discord bot auto respond to a message? 我如何获取我的 discord 机器人所在频道的频道 ID 以及消息作者的频道 ID - How do i get the id of the channel the channel my discord bot is in and the channel id of the message author 如何向我的机器人在 v14 discord.js 中的所有 discord 服务器发送消息? - How would I send a message to all discord servers my bot is in v14 discord.js? 我的 Discord.js Bot 欢迎消息突然停止工作 - My Discord.js Bot welcome message suddenly stopped working 如何让我的 discord 机器人对提到的它做出反应? - How do I get my discord bot react to it being mentioned?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM