【发布时间】:2021-09-19 02:11:36
【问题描述】:
我的机器人在收到某个 message.content 后创建了一个不和谐频道,我需要获取其创建的频道 ID 以便在消息中显示它。 我的代码:
client.on('message', message =>{
if(message.content === (prefix + 'report')) {
message.guild.channels.create (`Репорт (${message.author.tag})`, {
type: 'voice',
permissionOverwrites: [
{
id: '861645891848110100',
deny: 'VIEW_CHANNEL',
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'STREAM', 'SPEAK', 'CONNECT','USE_VAD'],
deny: ['PRIORITY_SPEAKER', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'CREATE_INSTANT_INVITE', 'MANAGE_ROLES', 'MANAGE_CHANNELS'],
},
{
id: moderRole,
allow: ['VIEW_CHANNEL', 'STREAM', 'SPEAK', 'CONNECT', 'USE_VAD', 'PRIORITY_SPEAKER', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'MANAGE_ROLES', 'CREATE_INSTANT_INVITE'],
deny: ['MANAGE_CHANNELS'],
},
],
reason: `${message.author.tag} sended report`,
})
const msg1 = new Discord.MessageEmbed()
.setTitle(`Обращение успешно отправленно!`)
.setDescription(`<@${message.author.id}>, просим вас зайти в канал <#$> и ждать пока вас переместят для разбирательств.`)
message.reply(msg1)
message.delete()
}
})
新变化
好的,我稍微改了一下代码,现在看起来是这样的:
client.on('message', async message => {
if(message.content === (prefix + 'report')) {
const channel = await message.guild.channels.create(
message.guild.channels.create (`Репорт (${message.author.tag})`, {
type: 'voice',
permissionOverwrites: [
{
id: '861645891848110100',
deny: 'VIEW_CHANNEL',
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'STREAM', 'SPEAK', 'CONNECT','USE_VAD'],
deny: ['PRIORITY_SPEAKER', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'CREATE_INSTANT_INVITE', 'MANAGE_ROLES', 'MANAGE_CHANNELS'],
},
{
id: moderRole,
allow: ['VIEW_CHANNEL', 'STREAM', 'SPEAK', 'CONNECT', 'USE_VAD', 'PRIORITY_SPEAKER', 'MUTE_MEMBERS', 'DEAFEN_MEMBERS', 'MOVE_MEMBERS', 'MANAGE_ROLES', 'CREATE_INSTANT_INVITE'],
deny: ['MANAGE_CHANNELS'],
},
],
reason: `${message.author.tag} sended report`,
}))
const msg1 = new Discord.MessageEmbed()
.setTitle(`Обращение успешно отправленно!`)
.setDescription(`<@${message.author.id}>, просим вас зайти в канал <#${channel.id}> и ждать пока вас переместят для разбирательств.`)
message.reply(msg1)
message.delete()
}
})
但我在测试后收到以下错误:
(node:1344) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
name: Could not interpret "{}" as string.
at RequestHandler.execute (a:\Wiki Cheats\discord bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async RequestHandler.push (a:\Wiki Cheats\discord bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
at async GuildChannelManager.create (a:\Wiki Cheats\discord bot\node_modules\discord.js\src\managers\GuildChannelManager.js:112:18)
at async Client.<anonymous> (a:\Wiki Cheats\discord bot\index.js:35:29)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1344) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1344) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
标签: javascript discord.js