[英]How can I get the channel ID of the channel that a Discord bot's command was run in?
[英]How can I make a discord bot creates a channel on a command
你好呀
我目前正在使用名為“文件存儲”的 discord 服務器(名稱可能會更改),我想知道是否有一種方法:當用戶鍵入某個命令(例如“fs create”)時,機器人會創建像“channelid-storing”這樣的頻道只對使用該命令的用戶可見?
頻道名稱格式將顯示頻道 ID,然后顯示“-storing”
let client = new Discord.Client()
client.on("message", message => {
if(message.content === "ping") {
message.channel.send("pong")
}
client.on(message, async (message) => {
if(message === `>fs create`){
const channel = await message.guild.channels.create("channel", {
permissionOverwrites: [
{
id: message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"],
},
{
id: message.member,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
],
},
{
id: message.guild.me,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
],
},
],
});
channel.editName(`${channel.id}-store`)
}
})
})
client.login(process.env.DISCORD_TOKEN);```
創建頻道時,您只需提供用戶權限
if(commandname === `> fs create`){
const channel = await message.guild.channels.create("channelname", {
permissionOverwrites: [
{
id: message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"],
},
{
id: message.member,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
],
},
{
id: message.guild.me,
allow: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
],
},
],
});
channel.editName(`${channel.id}-store`)
}
順便說一句,你必須添加你的東西,這樣它才能正常工作,上面的例子展示了頻道創建的工作原理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.