(client, channel, guildId, newOwnerId)
| 252 | } |
| 253 | |
| 254 | async function transferChannelOwnership(client, channel, guildId, newOwnerId) { |
| 255 | try { |
| 256 | const config = await getJoinToCreateConfig(client, guildId); |
| 257 | const tempChannelInfo = config.temporaryChannels[channel.id]; |
| 258 | |
| 259 | if (!tempChannelInfo) return; |
| 260 | |
| 261 | config.temporaryChannels[channel.id].ownerId = newOwnerId; |
| 262 | await client.db.set(`guild:${guildId}:jointocreate`, config); |
| 263 | |
| 264 | const newOwner = await channel.guild.members.fetch(newOwnerId); |
| 265 | if (newOwner) { |
| 266 | const channelOptions = config.channelOptions?.[tempChannelInfo.triggerChannelId] || {}; |
| 267 | const nameTemplate = channelOptions.nameTemplate || config.channelNameTemplate; |
| 268 | |
| 269 | const newChannelName = sanitizeVoiceChannelName(formatChannelName(nameTemplate, { |
| 270 | username: newOwner.user.username, |
| 271 | userTag: newOwner.user.tag, |
| 272 | displayName: newOwner.displayName, |
| 273 | guildName: channel.guild.name, |
| 274 | channelName: channel.guild.channels.cache.get(tempChannelInfo.triggerChannelId)?.name || 'Voice Channel' |
| 275 | })); |
| 276 | |
| 277 | await channel.setName(newChannelName); |
| 278 | } |
| 279 | |
| 280 | logger.info(`Transferred ownership of temporary channel ${channel.id} to user ${newOwnerId}`); |
| 281 | |
| 282 | } catch (error) { |
| 283 | logger.error(`Failed to transfer ownership of channel ${channel.id}:`, error); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | }; |
| 288 |
no test coverage detected