Trying to make a Ticket Bot but gets TypeError: channel.updateOverwrite is not a function
Trying to make a Ticket Bot but gets TypeError: channel.updateOverwrite is not a function
我想制作一个工单系统,当您对 ✅ 做出反应时,在工单中仅从管理员那里查看频道。 (关闭工单。)
代码:
if (reaction.emoji.name === "✅") {
if(!reaction.message.channel.name.includes('ticket-')) return
reaction.users.remove(user)
reaction.message.reactions.cache.get('✅').remove()
reaction.message.reactions.cache.get('❌').remove()
let channel = reaction.message
channel.updateOverwrite("user.id", { VIEW_CHANNEL: false });
}
错误:
TypeError: channel.updateOverwrite is not a function
首先,channel
不是 GuildChannel
but of Message
, which is probably a mistake. To get the corresponding GuildChannel
object, use the following: (as PerplexingParadox said in their 的实例。)
let channel = reaction.message.channel;
接下来就是 Collection.get()
method accepts a key as its parameter, which is in this case the reaction id (or Twitter Snowflake)。要按名称查找反应,您可以这样做:
for (const emojiName of ["✅", "❌"]) {
reaction.message.reactions.cache.find((reaction) => {
return reaction.emoji.name === emojiName;
})?.remove();
}
如果使用 optional chaining operator.
找到它们,则将其删除
最后 GuildChannel.updateOverwrite()
accepts RoleResolvable
or UserResolvable
作为它的第一个参数。传入用户 ID 是正确的,因为它属于 UserResolvable
。您可能不小心在 user.id
周围添加了引号。它是一个变量,如果你想把它当作一个变量来处理,去掉引号,否则它只会被当作一个带有文本的字符串。并且不会工作,因为文本“user.id”不是有效的 Twitter 雪花。
channel.updateOverwrite(user.id, { VIEW_CHANNEL: false });
我想制作一个工单系统,当您对 ✅ 做出反应时,在工单中仅从管理员那里查看频道。 (关闭工单。)
代码:
if (reaction.emoji.name === "✅") {
if(!reaction.message.channel.name.includes('ticket-')) return
reaction.users.remove(user)
reaction.message.reactions.cache.get('✅').remove()
reaction.message.reactions.cache.get('❌').remove()
let channel = reaction.message
channel.updateOverwrite("user.id", { VIEW_CHANNEL: false });
}
错误:
TypeError: channel.updateOverwrite is not a function
首先,channel
不是 GuildChannel
but of Message
, which is probably a mistake. To get the corresponding GuildChannel
object, use the following: (as PerplexingParadox said in their
let channel = reaction.message.channel;
接下来就是 Collection.get()
method accepts a key as its parameter, which is in this case the reaction id (or Twitter Snowflake)。要按名称查找反应,您可以这样做:
for (const emojiName of ["✅", "❌"]) {
reaction.message.reactions.cache.find((reaction) => {
return reaction.emoji.name === emojiName;
})?.remove();
}
如果使用 optional chaining operator.
找到它们,则将其删除最后 GuildChannel.updateOverwrite()
accepts RoleResolvable
or UserResolvable
作为它的第一个参数。传入用户 ID 是正确的,因为它属于 UserResolvable
。您可能不小心在 user.id
周围添加了引号。它是一个变量,如果你想把它当作一个变量来处理,去掉引号,否则它只会被当作一个带有文本的字符串。并且不会工作,因为文本“user.id”不是有效的 Twitter 雪花。
channel.updateOverwrite(user.id, { VIEW_CHANNEL: false });