#Changing format count, want to tag channel

1 messages · Page 1 of 1 (latest)

muted plume
#

Hi, so i have a text input with first {user.mention}. Now i have a changing number of: {#channel-name-here}. How can i send this the best with formatting?

hallow summit
#

like a "member stat channel"?
that updates as member count changes?

#

Oh..

#

channel.mention is a thing

#

doesn't matter what the name of the channel is

muted plume
hallow summit
#

IDs are not static and do not care what the channel name is

#

If you don't know the ID because you're creating/removing channels, then you'll need to get the channel ID by getting the channel object by name.

muted plume
#

Like: i have a text that a user fills in:

hi {user}
Check channel {channel_name} and {channel_name_again}

This get the bots, and send it

hallow summit
#
channel = disnake.utils.get(guild.channels, name=CHANNEL_NAME)

channel.mention
muted plume
#

But the text xchange from time to time

#

I want basicly this. There can be 1 channel, 10 channels in the message

#

If the bot gets a string from a file for example, you cant just 1 time do channel.mention, because place and channel count changes every time

#

Like this is the modal.

#

This is how it sends now. I know formatting, but if there are 2 times {#channel_name_here} then formatting isnt correct anymore

hallow summit
#

It's impossible to mention with a name.

#

You would HAVE to get the channel ID some way.

muted plume
hallow summit
#

Looks like you'll need regex to find all instances of {#sometext}

muted plume
#

Dont mind the uglyness, just testing and trying haha

hallow summit
#

then get or fetch the channel object to get the ID.

muted plume
#

I'm on it, i will post the result here! 🙂

hallow summit
#

It's quick and dirty, but you could then do something like this:

matched_channels = re.findall(r"\{#\w+\}", content)

for matched_ch in matched_channels:
    # strip the extra chars fro the channel name
    channel_name = matched_ch.lstrip('{#').rstrip('}')
    # get the channel object by its name
    channel = disnake.utils.get(inter.guild.channels, name=channel_name)
    # replace the instance of "{#channel-name}" with mention in content
    content.replace(matched_ch, channel.mention)