Skip to content

Commit 506576e

Browse files
noftalykyranet
andauthored
feat(resolver): make resolveChannel parse mentions (#253)
Co-authored-by: Antonio Román <[email protected]>
1 parent 1848f53 commit 506576e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib/resolvers/channel.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import type { ChannelTypes } from '@sapphire/discord.js-utilities';
1+
import { ChannelMentionRegex, ChannelTypes } from '@sapphire/discord.js-utilities';
22
import { container } from '@sapphire/pieces';
33
import type { Message, Snowflake } from 'discord.js';
44
import { Identifiers } from '../errors/Identifiers';
55
import { err, ok, Result } from '../parsers/Result';
66

77
export function resolveChannel(parameter: string, message: Message): Result<ChannelTypes, Identifiers.ArgumentChannelError> {
8-
const channel = (message.guild ? message.guild.channels : container.client.channels).cache.get(parameter as Snowflake);
8+
const channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake;
9+
const channel = (message.guild ? message.guild.channels : container.client.channels).cache.get(channelId);
910
if (channel) return ok(channel as ChannelTypes);
1011
return err(Identifiers.ArgumentChannelError);
1112
}

0 commit comments

Comments
 (0)