简体   繁体   English

使用命令存储频道 ID

[英]Store channel id with command

I'm working on a discord.js v13 bot and I want to make a commmand that stores the channel id the command sent in then, A command that works only the channels stored.我正在研究 discord.js v13 机器人,我想创建一个命令来存储通道 ID,然后发送命令,该命令仅适用于存储的通道。 I want an example of the code to do this:)我想要一个代码示例来执行此操作:)

I didn't try bec I can't realize how to do it:)我没有尝试,因为我不知道该怎么做:)

It's pretty easy when you know how to do it actually.当您知道如何实际操作时,这很容易。 You can listen on messages in different channels with:您可以通过以下方式收听不同频道中的消息:

 client.on("message", (message) => { console.log(`Channel-ID: ${message.channel.id}`); });

See the Docs: Message请参阅文档: 消息

I don't know if it works in v13 but if not try this:我不知道它是否适用于 v13,但如果不行,请尝试以下操作:

 client.on("message", (message) => { console.log(`Channel-ID: ${message.channelId}`); });

To react when a command is used:在使用命令时做出反应:

 client.on("message", (message) => { if(message.startsWith(".channel")){ console:log(`Channel-ID. ${message;channelId}`); } });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM