Jim*_*nee 2 javascript discord
我正在制作一个不和谐的机器人,并且试图利用文档中此处显示的createChannel函数。由于某种原因,我收到以下错误:
TypeError:bot.createChannel不是函数。
我的代码在传递消息的功能中,并且能够创建角色并将用户添加到同一功能中的角色中。只是createChannel函数不起作用。以下是代码的相关部分。
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);
}
Run Code Online (Sandbox Code Playgroud)
我还尝试了bot.addChannel和bot.ChannelCreate,因为ChannelCreate.js是包含此命令代码的文件的名称。另外,我尝试指定通道类型并分配回调函数,但是主要问题是TypeError说这根本不是一个函数。知道我在做什么错吗?
另外,我计划在将来的某个时候使用ServerChannel.update(),因此,一旦解决了先前的问题,就可以使它正常工作的任何建议将不胜感激。
答案应该更新GuildChannelManager现在负责创建新频道的文档链接。
(来自文档的示例)
// Create a new text channel
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
.then(console.log)
.catch(console.error);
Run Code Online (Sandbox Code Playgroud)
https://discord.js.org/#/docs/main/stable/class/GuildChannelManager
好了,经过几天的尝试并仔细阅读了文档,我找到了解决方案。我使用的Discord版本不是我正在阅读的文档的最新版本。在较新的版本中,通道是使用服务器中的方法而不是客户端方法创建的。因此,代码应为:
const bot = new Discord.Client();
function makeChannel(message){
var server = message.guild;
var name = message.author.username;
server.createChannel(name, "text");
}
Run Code Online (Sandbox Code Playgroud)
“文本”值是您制作的频道的类型。可以是文字或语音。
我将在此处发布指向任何遇到此问题的其他人的最新文档的链接。
| 归档时间: |
|
| 查看次数: |
17278 次 |
| 最近记录: |