#Changing format count, want to tag channel
1 messages · Page 1 of 1 (latest)
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
But i cant do that. Thats static
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.
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
No look
channel = disnake.utils.get(guild.channels, name=CHANNEL_NAME)
channel.mention
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
It's impossible to mention with a name.
You would HAVE to get the channel ID some way.
I got a way:
found = re.findall('{(.+?)}', content)
for thing in found:
if "#" in thing:
get_name = str(thing).split("#")[1]
print(get_name)
channel = disnake.utils.get(bot.get_all_channels(), guild__name=str(get_name))
channel_id = channel.id```
Looks like you'll need regex to find all instances of {#sometext}
Dont mind the uglyness, just testing and trying haha
then get or fetch the channel object to get the ID.
I'm on it, i will post the result here! 🙂
probably want this: r"\{#\w+\}"
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)