How to create a text channel

旧巷老猫 提交于 2019-12-13 18:18:37

问题


Recently I have been making a discord bot, and I wanted to make a channel once the players have entered the command >report [Tag] [Reason].

Here are the two methods I have tried (one from a previous StackOverflow question that did not work for me):

function makeChannel(message){
    var server = message.guild;
    var name = message.author.username;

    server.createChannel(name, "text");
}

Then I tried my own version to see if I could do it:

var name = message.author.username;
let reportchannel = server.createChannel(name, "text");

message.createChannel(reportchannel);

Yet neither work, and I am dying for help!

Thanks for the help and suggestions, greatly appreciated!


回答1:


As seen here the proper way to create a text channel (and since you're using the message variable I'm going to assume you're in the message event)

let name = message.author.username;
message.guild.createChannel(name, 'text')
.then(console.log)
.catch(console.error);

Also, another suggestion I have is to use let instead of var because this reason

edit: Just noticed the main reason this isn't working for you is because you're using message.createChannel() and note message.guild.createChannel()



来源:https://stackoverflow.com/questions/54099201/how-to-create-a-text-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!