I have a mute command in my bot but i want to add a timer on it, not really sure how to tho, this is my current code. It adds the code correctly and it all sends correctly but the duration i'm not really sure about. Any help would be appreciated!
Edit: I got the duration working, but how would i convert it into minutes/hours etc.?
#client.command()
#commands.has_permissions(manage_messages=True)
async def mute(ctx, member: discord.Member, mute_time : int, *, reason=None):
role = discord.utils.get(ctx.guild.roles, name="[Muted]")
await member.add_roles(role)
await ctx.send(f'**Muted** {member.mention}\n**Reason: **{reason}\n**Duration:** {mute_time}')
embed = discord.Embed(color=discord.Color.green())
embed.add_field(name=f"You've been **Muted** in {ctx.guild.name}.", value=f"**Action By: **{ctx.author.mention}\n**Reason: **{reason}\n**Duration:** {mute_time}")
await member.send(embed=embed)
await asyncio.sleep(mute_time)
await member.remove_roles(role)
await ctx.send(f"**Unmuted {member.mention}**")
I use your code in minimal example and it's work well. What problems do you have? Example:
#client.command()
#commands.has_permissions(manage_messages=True)
async def mute(ctx, mute_time : int):
await ctx.send("Muted")
await asyncio.sleep(mute_time)
await ctx.send("Unmuted")
Exactly one minute passed. Result:
Related
This is my code
#bot.command()
async def say(ctx, message=None):
await ctx.message.delete()
await ctx.send(message)
However, if I do !!say I’m a dog, the bot will say only I’m
Can you help me please?
That's because space is an argument separator. If you want to have an argument with spaces use * in your function. Like this:
#bot.command()
async def say(ctx,*,message=None):
await ctx.message.delete()
await ctx.send(message)
I don't have much experience in discord.py, but I'm making a bot. Right now I added the welcoming message:
#client.event
async def on_member_join(member):
channel=client.get_channel(channel_ID)
emb=discord.Embed(title="NEW MEMBER",description=f"Thanks {member.name} for joining!")
await channel.send(embed=emb)
but I want to mention the user who joined as this picture
May you help me doing this? Thanks!
Use member.mention
This returns a string which allows you to mention the member.
#client.event
async def on_member_join(member):
channel=client.get_channel(channel_ID)
emb=discord.Embed(title="NEW MEMBER",description=f"Thanks {member.mention} for joining!")
await channel.send(embed=emb)
You should however keep in mind that because of caching, the mention will most likely look something like this <#!123456789>.
You need the code to look like this:
#client.event
async def on_member_join(member):
if member.guild.id !=Guild.id:
return
channel = client.get_channel(channel_id) # replace id with the welcome channel's id
await channel.send(f"{member.mention} has arrived!, check out our announcments channel for server and bot announcements!")
await member.send(f"Thank you for joining {member.guild.name}!")
This line right here is you only want people that join YOUR server to send a msg, if you don't have any server with your bot in it, will say the msg still
if member.guild.id !=Guild.id:
return
{member.mention} is what mentions the user if you are using {} in the sending part you need the f function
Next code will make the code call the {}
await channel.send(f"{member.mention}")
This calls the guild name:
{member.guild.name}
I am not sure about client.get_channel, but you sure can try this:
#client.event
async def on_member_join(member):
guild = client.get_guild(serverID)
channel = guild.get_channel(channelID)
emb = discord.Embed(title="NEW MEMBER",description=f"Thanks {member.name} for joining!")
await channel.send(member.mention, embed=emb)
I'm trying to make and event that checks to see if the channel id is equal to a specific id, if it is then the bot adds a reaction to that message. I'm not quite sure how to do this and have looked up many solutions but none of them help. There are some errors in the code that I still have to figure out like channel.id is not and actual command. Here is my code:
#client.event
async def on_message(message):
await discord.Client.get_channel(<channel_id>)
if channel.id == <channel_id>:
await message.add_reaction("✔️")
await message.add_reaction("❌")
discord.Client is a type, not a instance. And there is a message property inside discord.Message.
#client.event
async def on_message(message):
if message.channel.id == <channel_id>:
await message.add_reaction("✔️")
await message.add_reaction("❌")
Alright, what I need is to put autorole code to my bot but only for specific server.
So please, help me!
Here is the code so far but I made it only beacuse stack overflow can't accept my text body:
#client.event
async def on_member_join(member : discord.Member):
server = ctx.message.server
rolelol = client.get_role('770262439937048577')
if server == server.id:('753667215710224574'):
await client.add_roles(member, rolelol)
else:
await client.say('')
All I need is code for autorole this doesn't code i made doesn't really matter...
You have a few things wrong :
add_roles is a Member object method, so you have to use member.add_roles()
ctx isn't defined since you're not in a command, to get the discord guild object, you have to write member.guild
get_role() is a Guild object method so you need to write member.guild.get_role(id)
Your IDs need to be passed as int, not str.
Client objects don't have any say() method
With all thoses changes, your code would look like this :
#client.event
async def on_member_join(member : discord.Member):
role = member.guild.get_role(770262439937048577)
if member.guild.id == 753667215710224574:
await member.add_roles(role)
Reference : https://discordpy.readthedocs.io/en/latest/
This is the code I am using currently:
#client.command()
async def say(ctx, arg: str):
await ctx.channel.purge(limit=1)
await ctx.send(f"{arg}")
This code works, but the bot only says the first word of the sentence. How can I make it say the whole sentence?
I hope this would work:
#client.command()
async def say(ctx, *args):
await ctx.message.delete()
# do you want to say it with TTS ?
await ctx.send(' '.join(args), tts=True)