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)
Related
So I wanted to make a feature on my discord bot and I wanted it to respond when users say welcome and say Welcome! back. But every time I try it only responds to $welcome. ($ is my prefix). What should I do?
client = commands.Bot(command_prefix = "$")
#client.command()
async def welcome(ctx, message):
if any(word in message for word in welcome):
await message.channel.send("Welcome!")
#client.event
async def on_message(message):
if "welcome" in message.content:
await message.channel.send('Welcome!')
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 have problem with my discord.py command. I want to make ping command which will respond with my bot's ping. My code is below.
#bot.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(bot.latency * 1000)}ms**"
I also tried to write my code like this.
#client.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(bot.latency * 1000)}ms**"
None of the above code works.
I have this command and I've tested it to know it works.. you can try it:
#bot.command()
async def ping(ctx):
await ctx.send(f'My ping is** {round(bot.latency*1000)} Ms**')
Btw, if you have defined bot as client, make sure to change bot.latency to client.latency
Did you add a bracket to the end?
#bot.command() # set this to your bots variable
async def ping(ctx):
await ctx.send(f"Ping!\nLatency is **{round(bot.latency * 1000)}ms**!")
embed = discord.Embed(
title="🏓 Pong!",
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
color=0x42F56C
)
await ctx.send(embed=embed)
The problem with your code is that you forgot the ) between ms** and ".
#bot.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(bot.latency * 1000)}ms**")
This is the code fixed, if you want to use #client, just use this:
#client.command()
async def ping(ctx):
await ctx.send(f"Pong :ping_pong:! Bot latency: **{round(client.latency * 1000)}ms**")
I am attempting to add an automod cog to my discord bot. I have written a blacklist command and whitelist command in a different file and they work fine. What i can't figure out is when it loads the blacklisted words from the .csv file it loads them to the variable as ["['Test']"] and not as Test. If anyone knows how to fix this please let me know.
class AutoMod(commands.Cog):
def __init__ (self, bot):
self.bot = bot
self.words = Words
#commands.Cog.listener()
async def on_ready(self):
self.words = {}
with open(Wdir, 'r') as csv_file:
csvreader=csv.reader(csv_file)
for line in csvreader:
Words.append(str(line))
print(f'AutoMod {Words}')
#commands.Cog.listener()
async def on_message(self, message):
print(Words)
if str(Words) in message.content:
await message.delete()
await message.channel.send(f'{message.author.mention}, You are not allowed to say that')
else:
pass
def setup(bot):
bot.add_cog(AutoMod(bot))
You can do smth like this:
filtered_words = ["badword", "verybadword"]
#client.event
async def on_message(message):
for word in filtered_words:
if word in message.content:
await message.delete()
await message.channel.send("This word is blacklisted")
await client.process_commands(message)
Now bot will delete a message that contains any of filtered words. Bot will also send a message that says word is blacklisted.
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: