Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  123] [ 2]  / answers: 1 / hits: 58438  / 7 Years ago, thu, april 20, 2017, 12:00:00

I'm making a discord bot, and I'm trying to make use of the createChannel function shown here in the documentation. For some reason, I am getting the following error:



TypeError: bot.createChannel is not a function.



My code is within a function which I pass a message to, and I have been able to create roles and add users to roles within the same function. It's just the createChannel function that's not working. Below is the relevant portions of the code.



const bot = new Discord.Client();

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

server.createRole(data);
var newrole = server.roles.find(name, name);
message.author.addrole(newrole);

/* The above 3 lines all work perfectly */


bot.createChannel(server,name);
}


I have also tried bot.addChannel, and bot.ChannelCreate, since ChannelCreate.js is the name of the file which contains the code for this command. Also, I have attempted specifying channel type and assigning a callback function as well, but the main issue is the TypeError saying that this isn't a function at all. Any idea what I'm doing wrong?



Additionally, I plan to use ServerChannel.update() at some point in the future, so any advice on getting that to work once the previous problem is resolved would be greatly appreciated.


More From » discord

 Answers
14

Alright, after a few days of trying things and going through the docs, I have discovered the solution. I am using a more recent version of Discord than the docs I was reading were written for. In the newer version, channels are created with a method in the server, not a client method. so, the code should be:



const bot = new Discord.Client();

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

server.createChannel(name, text);
}


The text value is the type of channel you are making. Can be text or voice.



I'll post a link to the most recent documentation for anyone else who encounters this problem here.


[#58083] Tuesday, April 18, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
manuel

Total Points: 747
Total Questions: 96
Total Answers: 95

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
;