Reputation: 1
Hey so this is my code and I want that the bot dms the member with 'test'
@has_permissions(kick_members=True)
@client.command()
async def kick(ctx, member: discord.Member, *, reason=None):
embed_kick = discord.Embed(title=f'Kick command usage')
embed_kick.set_footer(text=f'VexArtz Community Discord')
embed_kick.add_field(name=f'Kicked user', value=f'{member}', inline=True)
embed_kick.add_field(name=f'Reason', value=f'-{reason}', inline=True)
embed_kick.add_field(name=f'Author', value=f'{ctx.author.mention}', inline=True)
await member.kick(reason=reason)
await ctx.channel.purge(limit=1)
log_channel = client.get_channel(858716439849861121)
await log_channel.send(embed=embed_kick)
Upvotes: 0
Views: 187
Reputation: 43
- You can use
fetch_user
method to get a member.create_dm
Creates a DMChannel with user. This should be rarely called, as this is done transparently for most people.
Well, now that we have taken the member and created a DM Channel object, we can now send a message to the member or the same user with this object.
@has_permissions(kick_members=True)
@client.command()
async def kick(ctx, member: discord.Member, *, reason=None):
embed_kick = discord.Embed(title=f'Kick command usage')
embed_kick.set_footer(text=f'VexArtz Community Discord')
embed_kick.add_field(name=f'Kicked user', value=f'{member}', inline=True)
embed_kick.add_field(name=f'Reason', value=f'-{reason}', inline=True)
embed_kick.add_field(name=f'Author', value=f'{ctx.author.mention}', inline=True)
user = await client.fetch_user(member.id) #Fetch the user with its id
dm = await user.create_dm() #If dm is already made, it does not matter :)
await dm.send("test")
await member.kick(reason=reason)
await ctx.channel.purge(limit=1)
log_channel = client.get_channel(858716439849861121)
await log_channel.send(embed=embed_kick)
We could use the same member.send()
, but errors may occur.
Such as:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
Upvotes: 1
Reputation: 2289
You can send a message to a user via member.send()
. I guess you want to send a message to the user being kicked? In that case you code could look something like this
@has_permissions(kick_members=True)
@client.command()
async def kick(ctx, member: discord.Member, *, reason=None):
embed_kick = discord.Embed(title=f'Kick command usage')
embed_kick.set_footer(text=f'VexArtz Community Discord')
embed_kick.add_field(name=f'Kicked user', value=f'{member}', inline=True)
embed_kick.add_field(name=f'Reason', value=f'-{reason}', inline=True)
embed_kick.add_field(name=f'Author', value=f'{ctx.author.mention}', inline=True)
await member.send(content = "test") # send message to member being kicked
await member.kick(reason=reason)
await ctx.channel.purge(limit=1)
log_channel = client.get_channel(858716439849861121)
await log_channel.send(embed=embed_kick)
Upvotes: 0