dpytest icon indicating copy to clipboard operation
dpytest copied to clipboard

Guild.unban(User) Not Implimented

Open kellentow opened this issue 4 months ago • 2 comments

  File "~/Coding/Linux/python/discord/cogs/admin.py", line 77, in admin_unban
    await context.guild.unban(user)
  File "~/.local/lib/python3.12/site-packages/discord/guild.py", line 3979, in unban
    await self._state.http.unban(user.id, self.id, reason=reason)
  File "~/.local/lib/python3.12/site-packages/discord/ext/test/backend.py", line 89, in request
    raise NotImplementedError(
NotImplementedError: Operation occured that isn't captured by the tests framework. This is dpytest's fault, please reportan issue on github. Debug Info: DELETE https://discord.com/api/v10/guilds/2/bans/2 with {'reason': None}

Problem:

Guild.unban(User) is not mocked by dpytest

Temp solution:

from unittest.mock import AsyncMock
guild.unban = AsyncMock()

How to recreate:

import discord.ext.test as dpytest
user = dpytest.backend.make_user("tester")
dpytest.backend.make_guild(name="test").unban(user)

kellentow avatar Sep 25 '25 23:09 kellentow

This library is largely in maintenance mode. I would be willing to attempt to review and merge a PR adding this functionality.

CraftSpider avatar Oct 20 '25 22:10 CraftSpider

same for me. I'm not currently actively developping for the project, but I can merge a PR, if you propose one.

Sergeileduc avatar Oct 30 '25 21:10 Sergeileduc