#changing a regular dropdown into a persistent dropdown
1 messages · Page 1 of 1 (latest)
uhh
It works well, its just not persistent
Here's the persistent example.
i think you misunderstood how persistent views work, it relies on add_view and custom_id being assigned to the item
the example goes through initial creation and then making it persistent
Yes, I know. the way i add views, is the issue. You cannot use ctx, in a discord.ui.view considering it wont be defined, nor can I use await, that is how i add my selections from the dropdown menu
is it subclassed?
i'm not quite sure what the issue is, might be easier to visualize with the full code
I can create a subclassed one.
well it's not necessary, but just checking
for role in ctx.guild.roles:
if role.name in team:
options.append(discord.SelectOption(label=role.name, emoji= await find_by_name(role.name, ctx.guild.emojis)))
async def my_callbacks(interaction: discord.Interaction):
if select.values is None:
role = select2.values[0]
else:
role = select.values[0]
FO = []
GM = []
HC = []
CUSTOM = []
foRole = await find_by_name('Franchise Owner', ctx.guild.roles)
gmRole = await find_by_name('General Manager', ctx.guild.roles)
hcRole = await find_by_name('General Manager', ctx.guild.roles)
customRole = await find_by_name(role, ctx.guild.roles)
emoji = await find_by_name(customRole.name, ctx.guild.emojis)
for member in ctx.guild.members:
if foRole in member.roles and customRole in member.roles:
FO.append(f"{member.mention}``{member.name}``")
if gmRole in member.roles and customRole in member.roles:
GM.append(f"{member.mention}``{member.name}``")
if hcRole in member.roles and customRole in member.roles:
HC.append(f"{member.mention}``{member.name}``")
if customRole in member.roles:
CUSTOM.append(f"{member.mention}``{member.name}``")
i have more of which didn't fit into discord
so the top of that code is in a command?
Yes
what
Thats what needs to be out of the command
where are you trying to move it...? await works perfectly fine inside commands
on its own that code seems fine (albeit inefficient, but it looks like it'd work)
...why is find_by_name async anyway? this is a built in feature that's not async
Hmm..Its seems I am poorly explaining.
Ok so the code i just sent isn't persistent, and thats the issue all of the code i sent is indeed in side 1 command. However it is not persistent. I cannot make it persistent with this current code, because
class menu(discord.ui.View)
is where the code (the one you asked about), cannot be used inside this class considering async/await and ctx.
custom made function I made myself
can you show it?
from unicodedata import normalize
from discord.utils import find
from fuzzywuzzy.process import extract
def extract_conflicting_scores(extract_list):
"""Isolates objects in an array with matching fuzzywuzzy scores"""
list_builder = []
for i in extract_list:
if i[1] == extract_list[0][1]:
list_builder.append(i)
return list_builder
def build_conflicting_scores_string(conflicting_scores):
"""Builds a printable string from a conflicting scores list"""
string_builder = ""
for i in conflicting_scores:
string_builder += f"\n\"{i[0].name}\" match score: {i[1]}"
return string_builder
async def find_by_name(name: str, search_in):
"""Performs a fuzzy search with unicode-font conversions."""
found_name = extract(normalize("NFKC", name), [normalize("NFKC", item.name) for item in search_in])
found_items = [[find(lambda m: normalize("NFKC", m.name) == found[0], search_in), found[1]] for found in found_name]
# Check for match conflicts
if (
len(found_items) > 1
and found_items[0][1] == found_items[1][1]
):
# Create a warning string that tells the user what conflicts there are.
raise UserWarning(
f"Conflicting lookup found! Please provide more detail in your search of {name}.\n"
f"Conflicts:{build_conflicting_scores_string(extract_conflicting_scores(found_items))}"
)
return found_items[0][0]
it sorts through fonts
Yeah
and as such, you never need to await find_by_name
i can define guild so i wouldn't need ctx