为啥我的 Discord.js 欢迎消息中出现“无效的表单正文”错误?
Posted
技术标签:
【中文标题】为啥我的 Discord.js 欢迎消息中出现“无效的表单正文”错误?【英文标题】:Why am I getting an "invalid Form Body" error on my Discord.js welcome message?为什么我的 Discord.js 欢迎消息中出现“无效的表单正文”错误? 【发布时间】:2022-01-15 11:20:32 【问题描述】:我尝试发送欢迎信息,但出现错误。有谁知道如何解决这个错误?
代码:
const client = new Client(
allowedMentions: parse: ["users", "roles", "reaction"],
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_PRESENCES,
]
)
client.on(`guildMemberAdd` , (member, guild) =>
const arten = [
`Halli Hallo <@!$member.id>, Willkommen auf dem Teckles.net Server <:T_:788703077184045076>`,
`Willkommen <@!$member.id>, wir hoffen du hast viel Spaß auf Teckles.net <:T_:788703077184045076>`,
`<@!$member.id> hat sich dazu entschieden eine Runde mit uns zu spielen <:T_:788703077184045076>`,
]
const welcomemessage = `$arten[Math.floor(Math.random() * arten.length)]`
let roles = ['781625371682275360', `811351035209056307`, '811351288146821161', '811351128372936704', '828942314046357535']
for (number = 0; number < roles.length; number++)
let role = member.guild.roles.cache.find(r => r.id === roles[number])
member.roles.add(role)
const channel = client.channels.cache.find(channel => channel.id === '916730472950792252')
channel.send( content: welcomemessage)
)
错误:
DiscordAPIError: Invalid Form Body
allowed_mentions.parse[2]: Value must be one of ('roles', 'users', 'everyone').
at RequestHandler.execute (F:\Programmieren\Teckles\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (F:\Programmieren\Teckles\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async TextChannel.send (F:\Programmieren\Teckles\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:172:15)
method: 'post',
path: '/channels/916730472950792252/messages',
code: 50035,
httpStatus: 400,
requestData:
json:
content: 'Halli Hallo <@!777498801349853186>, Willkommen auf dem Teckles.net Server <:T_:788703077184045076>',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions:
parse: [ 'users', 'roles', 'reaction' ],
replied_user: undefined
,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
,
files: []
【问题讨论】:
【参考方案1】:MessageMentionTypes 只能是roles
、users
或everyone
。 reaction
与 MessageMentionTypes
不兼容。从client.allowedMentions.parse
中删除reaction
。
【讨论】:
以上是关于为啥我的 Discord.js 欢迎消息中出现“无效的表单正文”错误?的主要内容,如果未能解决你的问题,请参考以下文章
如何在 discord.js 上为 discord 服务器的新成员发送欢迎消息?