Discord uses special formatting for pings:
<@user_id>. With discord.py, there are two easy ways to ping a user:
# If you have the ctx object (inside a command) await ctx.send(ctx.message.author.mention) # If you have a message object (such as the on_message event) await message.channel.send(message.author.mention) # If you know their ID await ctx.send("<@" + str(user_id) + ">")
CTRL-R for running a program.
Doesn't appear to work on safari, but it works on Chrome, Chromium, and Brave
I see that people have answered your second question, but not the first. I don't think that there is a way to restart a python program from within the file, unless you put it in a function and just told it to re-run the function, then break the original, like this:
def main(): #main code here #to "restart" program: main() #this just re-runs the program that is currently running exit() #this tells the python program to stop completely main()
If you need a better example just let me know
I just noticed that when you except an error, you also re-run the function. This is not necessary because it is in a while loop and will re-run by itself.
except: print("Invalid input, Try Again")
except: print("Invalid input, Try Again") calc()
How come you're using sys to print to the screen, instead of
An easier way would probably be doing this:
def slow_print(text): for char in text: print(char, end='') #Print each individual character but don't go to a newline print() #Go to the next line (because 'end' defaults to '\n'
Here's what you can do. Define your variables at the top of your code, like
old_letter_guessed = 
and any other variables you have.
Then, when you use them inside of a function, do this instead:
def my_function(): global old_letter_guessed #Put this line at the top of your function.
This tells Python that you want the variable to update outside fo the function. Otherwise, the variable will stay inside the function, so to speak.
Hope this helps
SixBeeps has it. You have
main_character = input(str(">>>"("Are you sure?"))
main_character = input(str(">>>"("Are you sure?"))) (Note the extra
KeyError means that the key 'workspace' does not exist in the list. In this case, the list os.environ has not key 'workspace'
This simply means that there is no variable in os.environ called workspace. Maybe you meant
Amazing. Maybe add a password feature, so you can create a room, and set a password, so only those with the password can access
You would use
channel.purge() to do this. Here is an example command:
@bot.command(name="purge") @commands.has_guild_permissions(manage_messages=True) async def purge(ctx, limit: int): if limit > 1000: await ctx.send("You can only purge up to 1000 messages") return elif limit < 1: await ctx.send("You must purge at least 1 message") return await ctx.channel.purge(limit=limit)
Two things to note. First off, you are using
discord.Client instead of
discord.ext.commands.Bot. You should always use Bot, never use Client (unless you're making a self bot ig).
All you have to do is replace
client = discord.Client()
bot = discord.ext.commands.Bot(command_prefix="!")
Also, you should add this to your imports:
from discord.ext import commands
You can use typhinting to declare the type of a variable without giving it a value. However, python will not recognize it as a valid variable until you assign it a value.
my_int: int my_float: float print(my_int) # Results in error
I can think of two reason why python wouldn't let you set an int as None:
1. None is it's own type (NoneType) -- Just like an integer can't be a string, and integer cannot by None
2. Say I did set an int as None:
my_int = int(None). What would happen if I tried using that variable?
my_int > other_int wouldn't work,
my_int += 1 wouldn't work.
I hope this helps.
help clear gives
Error: 'clear' is not a valid command. even though
clear clears the console.