S
S
SenaK2020-06-16 10:25:36
Python
SenaK, 2020-06-16 10:25:36

How to send messages to a discord bot?

There are very serious problems. I want the bot to automatically send a PM message to the person who was unbanned with the message that he can return to the server again. If I write ctx.user.send, an error is thrown that this is a subclass, etc., etc. (I know that this is a subclass like author)

Here is the code itself:

#unban
@commands.has_permissions(administrator = True)
@client.command(pass_context = True)
async def unban(ctx, *, member):
    await ctx.channel.purge(limit = 1)
 
    banned_users = await ctx.guild.bans()
 
    for ban_entry in banned_users:
 
        user = ban_entry.user
        
        
        await ctx.guild.unban(user)
        await ctx.send(F"Добро пожаловать. Снова. {user.mention}")
        await ctx.user.send("Божество услышало твой зов, теперь снова можешь вернуться :3")        #https://discord.gg/
        return

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-06-16
@SenaK

Just use the "send" method on the user

@commands.has_permissions(administrator = True)
@client.command()
async def unban(ctx, *):
    await ctx.message.delete() # Для удаления сообщения с командой, если в оригинале подразумевалось это
 
    banned_users = await ctx.guild.bans()
 
    for ban_entry in banned_users:
        user = ban_entry.user
        await ctx.guild.unban(user)
        await ctx.send(f"Добро пожаловать. Снова. {user.mention}")
        await user.send("Божество услышало твой зов, теперь снова можешь вернуться :3")

Note: The bot will be able to send a message to the user only if the bot has a common server with the
user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question