discord.js - guild.createChannel 不起作用,我不知道为什么
问题描述
我已经尝试了一段时间,但我无法弄清楚这个。所以我想做的是使用机器人创建一个频道,这样一个人就可以打开一张票,基本上只有用户和特定角色可以查看和写入。我还没有完成第二部分,但这已经够糟糕了。
这是我可怜的尝试:
case 'report':
guild.createChannel('ticket-' + makeid, {
type: 'text',
permissionOverwrites: [{
id: guild.id,
deny: ['MANAGE_MESSAGES'],
allow: ['SEND_MESSAGES']
}]
})
.then(console.log)
.catch(console.error);
break;
在这种情况下,makeid是由函数生成的随机字符串。错误是:
ReferenceError: guild is not defined
解决方案
您需要定义变量guild
。有多种方法可以做到这一点Discord.js
,所以这里它们是:
使用用户消息:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', (message) => {
let guild = message.guild; //Get guild from the message
});
或者通过使用 GuildID:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on("ready", () => {
let guild = client.guilds.get("GUILD-ID"); //Replace "GUILD-ID" with the id of the guild you want
});
推荐阅读
- android - 如何使用 FusedLocationProviderClient 获取准确的位置(纬度和经度)
- java - 服务器应用程序挂起 Java socket 编程
- html - 如何去除按钮的底部空间?
- android - Ionic 3 对生产是否可靠?
- javascript - polymer-webpack-loader:如何导入和转译 Polymer .html 模板
- unity3d - 无法将拍摄的照片保存在 hololens 应用程序中
- php - 如何在 CodeIgniter 中生成自定义 ID?
- visual-studio - 如何使用不可复制不可移动类的对象成员函数启动线程?
- html - 在不加载 HTML 的情况下绑定 Angularjs 指令(bootstrap .modal('show'))
- javascript - 将数组转换为对象并将对象推入数组-javascript