I am attempting to mute a user.
#client.command()
#commands.has_permissions(administrator=True)
async def mute(ctx, user: discord.Member, *, reason=None):
await user.mute(reason=reason)
await ctx.send(f'{user} has been muted')
I receive the following error:
Member object has no attribute "mute"
How can I mute a user?
Try this:
#client.command()
#commands.has_permissions(administrator=True)
async def mute(ctx, user : discord.Member, *, reason = None):
await user.edit(mute = True, reason = reason)
await ctx.send(f'{user} has been muted')
Related
I'm wondering why I keep getting an error from it.
Here is my code:
#client.command()
#has_permissions(kick_members=True)
async def Kick(ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f'user {member} has been successfully kicked.')
#client.command()
#has_permissions(ban_members=True)
async def Ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'User {member} has been successfully banned.')
And here is the error:
File "X:\Discord Bot\The Crew.py", line 82
async def Kick(ctx, member : discord.Member, *, reason=None):
^
SyntaxError: invalid syntax
#client.command()
#has_permissions(ban_members=True)
async def Ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'User {member} has been successfully banned.')
Do Like This Instead
#commands.has_permissions(ban_members=True)
#commands.has_permissions(kick_members=True)
I've been looking into this issue, but only found webhooks that copy the author's name and avatar. I'd like to do the same, but with a tagged member's stuff.
trigger:
--say #test test
result:
#test test
This is my code so far:
#bot.command(pass_context=True)
async def say(ctx, *, message: str, member: discord.Member = None):
async with ClientSession() as session:
webhook = discord.Webhook.from_url(WEBHOOK_URL, adapter=discord.AsyncWebhookAdapter(session))
await webhook.send(content=message, username=member.Member.name, avatar_url=member.avatar_url)
Here is a working example of "impersonating" a user through a webhook, it takes the user's name and their profile picture but simply appears as a bot. It's the same method as bots such as "NQN" uses.
#client.command()
async def say(ctx, member: discord.Member, *, message=None):
if message == None:
await ctx.send(
f'Please provide a message with that!')
return
webhook = await ctx.channel.create_webhook(name=member.name)
await webhook.send(
str(message), username=member.name, avatar_url=member.avatar_url)
webhooks = await ctx.channel.webhooks()
for webhook in webhooks:
await webhook.delete()
Try this
#client.command()
async def impersonate(ctx, member: discord.Member, *, message=None):
if message == None:
await ctx.send(f'Who do you want to impersonate?')
return
webhook = await ctx.channel.create_webhook(name=member.name)
await webhook.send(
str(message), username=member.name, avatar_url=member.avatar_url)
await webhook.delete()
Could someone show how you'd restrict, for example, the following command to lets say a role named 'Moderator' or only to people that have kick permissions? I don't quite understand how that'd work.
#client.command()
async def kick(ctx, member:discord.Member)
await member.kick()
await ctx.send(f'{member.mention} has been kicked.')
To restrict commands to certain roles named "Moderator" or "Admin" use has_any_role
#client.command(pass_context=True)
#commands.has_any_role("Moderator", "Admin")
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.channel.send(f'{member.mention} has been kicked.')
To restrict commands to certain permissions of roles for example if a role has administrator you use has_permissions
#client.command(pass_context=True)
#commands.has_permissions(administrator=True)
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.channel.send(f'{member.mention} has been kicked.')
I need to check if a discord.Member is a bot in this command:
async def kick(ctx, user: discord.Member, *, reason="No Reason Provided"):
Thanks in advance!
#bot.command()
async def kick(ctx, user: discord.Member, *, reason="No reason provided"):
if not user.bot:
await user.kick(reason=reason)
await ctx.send(f"Successfully kicked {user}!")
else:
await ctx.send("You can't kick a bot!")
References:
Member.bot
Member.kick()
Im having an issue with my ban command, my admins can ban each otherr and i dont want that,but im not sure how to fix it here my code
#Ban command
#client.command()
#commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f'{user.mention} has been banned!')
I want it to make it like this but im pretty new to python and idk how to write it (the commented section)
#Ban command
#client.command()
#commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
#if mentioned user has the same role as the author:
await ctx.send('Cant ban Moderators/Admins')
else:
await member.ban(reason=reason)
await ctx.send(f'{user.mention} has been banned!')
#Ban command
#client.command()
#commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
check = False
for i in member.roles:
if i in ctx.author.roles[1:]:
check = True
if(check):
await ctx.send('Cant ban Moderators/Admins')
else:
await member.ban(reason=reason)
await ctx.send(f'{user.mention} has been banned!')