How can I send messages to the unbanned user and what did I dо wrong?

I have the unban function in my disnake bot. After I unban, the bot should send a personal message to the user, but I got an error there.

Code:

@bot.slash_command(name="unban",
                  description="Разбан пользователя (указание причины обязательно)"
                  )
@commands.has_permissions(ban_members=True)
async def unban(inter, member_id: str, reason: str):
    user = await bot.get_or_fetch_user(int(member_id))
    await inter.response.send_message(f'{user.mention} разбанен по причине: "{reason}".')
    await bot.guilds[0].unban(user, reason = reason)
    ban_list_channel = bot.get_channel(1274693427811844157)
    notification_channel = bot.get_channel(1274130140489580584)

    unban_embed = disnake.Embed(title = 'Пользователь разбанен!',
                              description = f'{user.mention} разбанен на сервере.n{ban_list_channel.mention} обновлен.',
                              color = disnake.Colour.yellow(),
                              timestamp= datetime.now()
                              )

    unban_embed_for_user = disnake.Embed(title = 'Вы были разбанены!',
                              description = f'{user.mention} разбанен на сервере {bot.guilds[0].name}.nПричина: "{reason}"nПриглашаем вас: https://discord.gg/hwQM6GG4kB',
                              color = disnake.Colour.green(),
                              timestamp= datetime.now()
                              )

    lines = []

    with open('source/txt/ban_list.txt', 'r') as ban_list:
            line = ban_list.readline()
            if str(member_id) not in line:
                lines.append(line)
            while line:
                line = ban_list.readline()
                if str(member_id) not in line:
                    lines.append(line)

    with open('source/txt/ban_list.txt', 'r+') as ban_list:
        ban_list.truncate()
        for line in lines:
            ban_list.write(line)
        text = ban_list.read()

    await notification_channel.send(embed = unban_embed)
    await ban_list_channel.purge(limit=3)

    ban_list_embed = disnake.Embed(title = 'Список забаненных пользователей:',
                              description = text,
                              color = disnake.Colour.red(),
                              timestamp= datetime.now()
                              )

    await ban_list_channel.send(embed = ban_list_embed)

    await asyncio.sleep(3)
    await inter.delete_original_message()
    await user.send(embed = unban_embed_for_user)

This is the error:

Ignoring exception in slash command 'unban':
Traceback (most recent call last):
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsslash_core.py", line 728, in invoke
    await call_param_func(self.callback, inter, self.cog, **kwargs)
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsparams.py", line 1083, in call_param_func
    return await maybe_coroutine(safe_call, function, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeutils.py", line 567, in maybe_coroutine
    return await value
           ^^^^^^^^^^^
  File "D:ds_bottrader.py", line 172, in unban
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeabc.py", line 1748, in send
    data = await state.http.send_message(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakehttp.py", line 409, in request
    raise Forbidden(response, data)
disnake.errors.Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this user

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsinteraction_bot_base.py", line 1378, in process_application_commands
    await app_command.invoke(interaction)
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsslash_core.py", line 737, in invoke
    raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this user

I tried to add a sleep function because I thought that the response from the server wasn’t delivered yet, but this thought is wrong.

I have three opinion,
User’s Privacy Settings: The user might have their privacy settings configured to disallow DMs from server members who are not friends. Or maybe The user might have blocked the bot, preventing it from sending DMs. maybe The user might have disabled receiving DMs from members of the server.

Have you update the disnake? It can be a library issue.

New contributor

bursow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How can I send messages to the unbanned user and what did I dо wrong?

I have the unban function in my disnake bot. After I unban, the bot should send a personal message to the user, but I got an error there.

Code:

@bot.slash_command(name="unban",
                  description="Разбан пользователя (указание причины обязательно)"
                  )
@commands.has_permissions(ban_members=True)
async def unban(inter, member_id: str, reason: str):
    user = await bot.get_or_fetch_user(int(member_id))
    await inter.response.send_message(f'{user.mention} разбанен по причине: "{reason}".')
    await bot.guilds[0].unban(user, reason = reason)
    ban_list_channel = bot.get_channel(1274693427811844157)
    notification_channel = bot.get_channel(1274130140489580584)

    unban_embed = disnake.Embed(title = 'Пользователь разбанен!',
                              description = f'{user.mention} разбанен на сервере.n{ban_list_channel.mention} обновлен.',
                              color = disnake.Colour.yellow(),
                              timestamp= datetime.now()
                              )

    unban_embed_for_user = disnake.Embed(title = 'Вы были разбанены!',
                              description = f'{user.mention} разбанен на сервере {bot.guilds[0].name}.nПричина: "{reason}"nПриглашаем вас: https://discord.gg/hwQM6GG4kB',
                              color = disnake.Colour.green(),
                              timestamp= datetime.now()
                              )

    lines = []

    with open('source/txt/ban_list.txt', 'r') as ban_list:
            line = ban_list.readline()
            if str(member_id) not in line:
                lines.append(line)
            while line:
                line = ban_list.readline()
                if str(member_id) not in line:
                    lines.append(line)

    with open('source/txt/ban_list.txt', 'r+') as ban_list:
        ban_list.truncate()
        for line in lines:
            ban_list.write(line)
        text = ban_list.read()

    await notification_channel.send(embed = unban_embed)
    await ban_list_channel.purge(limit=3)

    ban_list_embed = disnake.Embed(title = 'Список забаненных пользователей:',
                              description = text,
                              color = disnake.Colour.red(),
                              timestamp= datetime.now()
                              )

    await ban_list_channel.send(embed = ban_list_embed)

    await asyncio.sleep(3)
    await inter.delete_original_message()
    await user.send(embed = unban_embed_for_user)

This is the error:

Ignoring exception in slash command 'unban':
Traceback (most recent call last):
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsslash_core.py", line 728, in invoke
    await call_param_func(self.callback, inter, self.cog, **kwargs)
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsparams.py", line 1083, in call_param_func
    return await maybe_coroutine(safe_call, function, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeutils.py", line 567, in maybe_coroutine
    return await value
           ^^^^^^^^^^^
  File "D:ds_bottrader.py", line 172, in unban
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeabc.py", line 1748, in send
    data = await state.http.send_message(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakehttp.py", line 409, in request
    raise Forbidden(response, data)
disnake.errors.Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this user

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsinteraction_bot_base.py", line 1378, in process_application_commands
    await app_command.invoke(interaction)
  File "C:UsersIcoldAppDataLocalProgramsPythonPython311Libsite-packagesdisnakeextcommandsslash_core.py", line 737, in invoke
    raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this user

I tried to add a sleep function because I thought that the response from the server wasn’t delivered yet, but this thought is wrong.

I have three opinion,
User’s Privacy Settings: The user might have their privacy settings configured to disallow DMs from server members who are not friends. Or maybe The user might have blocked the bot, preventing it from sending DMs. maybe The user might have disabled receiving DMs from members of the server.

Have you update the disnake? It can be a library issue.

New contributor

bursow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật