discord.py MemberNotFound exception when passing a real member

2024/9/20 2:59:31

When I pass *grant @user add in Discord I get the following exception:

Ignoring exception in command grant:
Traceback (most recent call last):File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 902, in invokeawait ctx.command.invoke(ctx)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 856, in invokeawait self.prepare(ctx)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 790, in prepareawait self._parse_arguments(ctx)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 706, in _parse_argumentskwargs[name] = await self.transform(ctx, param)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 552, in transformreturn await self.do_conversion(ctx, converter, argument, param)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 505, in do_conversionreturn await self._actual_conversion(ctx, converter, argument, param)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 451, in _actual_conversionret = await instance.convert(ctx, argument)File "/Users/test/PycharmProjects/slapdash/venv/lib/python3.8/site-packages/discord/ext/commands/converter.py", line 191, in convertraise MemberNotFound(argument)
discord.ext.commands.errors.MemberNotFound: Member "<@!id> add" not found.

@user is a mention of myself in Discord and it's being recognized by Discord, tho not by my bot when converting to a Member. grant function's code (tho it's a private room perms system):

@bot.command()
async def grant(ctx, *, member: discord.Member = None, command=None):if (member is not None and  # if member argument providedcommand is not None and  # if command argument providedctx.channel.category_id in instances and  # if in dictionarymember.id != instances[ctx.channel.category_id]['admin_id'] and  # if not admincommand in ['add', 'remove', 'exit', 'grant', 'deny'] and(ctx.author.id == instances[ctx.channel.category_id]['admin_id'] or  # if adminctx.author.id in instances[ctx.channel.category_id]['granted']['grant_id_list']  # if granted)):if command == 'add' and member.id not in instances[ctx.channel.category_id]['granted']['add_id_list']:instances[ctx.channel.category_id]['granted']['add_id_list'].append(member.id)await ctx.send(f"Successfully granted to {member.mention}, but you'd better grant `remove` as well!")elif (member is not None and  # if member argument providedcommand is None and  # if command argument not providedctx.channel.category_id in instances and  # if in dictionarymember.id != instances[ctx.channel.category_id]['admin_id'] and  # if not admin(ctx.author.id == instances[ctx.channel.category_id]['admin_id'] or  # if adminctx.author.id in instances[ctx.channel.category_id]['granted']['grant_id_list']  # if granted)):if member.id not in instances[ctx.channel.category_id]['granted']['add_id_list']:  # if not addinstances[ctx.channel.category_id]['granted']['add_id_list'].append(member.id)if member.id not in instances[ctx.channel.category_id]['granted']['remove_id_list']:  # if not removeinstances[ctx.channel.category_id]['granted']['remove_id_list'].append(member.id)await ctx.send(f"Successfully granted `add` and `remove` to {member.mention}!")else:await ctx.send('Use `*help` to learn commands 😝')
Answer

You kind of messed up with the order of your arguments in your code I believe.

async def grant(ctx, *, member: discord.Member = None, command=None):

I think it should be this instead, so you can separate the command and the member.

async def grant(ctx, member: discord.Member = None, *, command=None):
https://en.xdnf.cn/q/119820.html

Related Q&A

using argument end= for print function in Python 3.3

Consider the following code:i=0 while i<5:print(i, end=" ")i = i + 1which results in the output:0 1 2 3 4if i want to add a string "the result" before 1 2 3 4, output expected: t…

Get the max value on a list of tuples

I have a list of tuples:card_list= [(2, (1, S)), (0, (12, H)), (1, (5, C)]This list contains cards: (cardindex, (value, suit)) where cardindex is a index to store the position of the card but irrelevan…

Naming of file while saving with extension

How can I save a file with the name as: oldname+"_new"+extension in an elegant way? I currently do: ext = os.path.splitext(file)[1] output_file = (root+/+ os.path.splitext(file)[0]+"_ne…

Unique permutations of a list without repetition

I understand there are many, many posts about permutations (unique, variable length, etc.), but I have not been able to use them to solve my particular issue.Lets say I have a list of metropolitan area…

Join Operation for Dictionary in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 3 years ago.Improve…

How to nest a list based on increasing sequences and ignore left overlapping ranges

This is my input mylist = [2, 7, 8, 11, 7, 9, 10, 15, 22, 30, 32]from 2 to 11, its increasing, so we need to grab the min max [2, 11] from 7 to 10 its increasing, but we need to ignore it because the …

Float comparison (1.0 == 1.0) always false

Im using the following function in Python 2.7.3 and Kivy 1.8.0 to fade-in a Grid widget:def __init__(self, **kwargs):# ...Init parent class here...self.grid.opacity = 0.0Clock.schedule_interval(self.sh…

How to I extract objects? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

sklearn.metrics.roc_curve only shows 5 fprs, tprs, thresholds [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 2 years ago.Improve…

I can not transform a file to a dictionary in python [duplicate]

This question already has answers here:ValueError: need more than 1 value to unpack python(4 answers)Closed 5 years ago.I am trying to transform a file to dictionary but having error.def txt_to_dict():…