I'm trying to follow a discord bot tutorial and I'm not sure how to fix an invalid syntax ctx error - syntax

I'm extremely new to coding, mainly just giving it a shot to attempt to make my own Discord bot. I'm not sure what I'm doing at all, so I've been following different youtube tutorials with varrying degrees of failure. The most recent one keeps saying a I have a syntax error, and I have no idea how to fix this. Here is the code:
1 import os
2 import discord
3 from discord.ext import commands
4
5 bot = commands.Bot(command_prefix="!", intents = discord.Intents.all()
6
7 #bot.command()
8 async def hello(ctx):
9 await ctx.send("Hello")
10 token = os.environ['TOKEN']
11 bot.run (token)
I have already used the secrets function to put the actual token in, and I've done my best to follow the tutorial as closely as possibly, but I am kind of clueless with this stuff so any help would be appreciated.
I've tried editing the text, adding quotations to the hello and removing them when realizing it did nothing to fix the problem. I'm at a loss.

Related

ThreeJS Modularity - Separating Three from html

I'm trying to make my little app a little more modular. It would be awesome if I could move all of the Three stuff out of the html page, and into its own js file.
Included "import * as THREE from 'three'" at the top of my JS, but couldn't figure out how to avoid "Cannot use import statement outside a module." Went with this: "let THREE= import("../build/three.module.js") " at the top of the module, which didn't give me the same error, but now it doesn't recognize "THREE".
Struggling through a number of different google searches, but haven't found what I'm looking for..
This was interesting: here but I either didn't understand it, or it didn't help me get where I needed to be.
Thoughts? Anything is much appreciated. Thanks.
Ok, looked harder, and found a couple of solutions. Posting links here.
Link 1 - Webpack Solution
Link 2 - Webpack Solution
Both are pretty good tutorials meant for someone going through this for the first time. (Like me.) One or both require payment at some point for the more in-depth topics. But - there are solutions for the problem above that are accessible for free.
Good luck.

IF statement and For

I'm a very, very n00b developper learning Python at university (I started a few weeks ago really) and I'm on my first assignment. Everything's going well, except one thing and i just can't figure it out. Or rather, I know what the problem is, but I can't find the solution. In short, I need to ask the user to input a number, and if number is 0, then the programs shows a message and stops there. Otherwise, it goes on with asking more info and uses For loops. My question is: How do I insert lines that are not part of the IF (user has entered 0) but also not part of any For loops (i don't want these lines repeated). I'm not sure if that makes any sense.
python code
basically i want the last print to be shown if the user has entered more than 0 in the beginning, but not be shown if the user has entered 0. I'm not showing the actual code, since it's a uni assignment, but the screenshot shows exactly the issue I'm having with the real code :) Thanks for your help!! (also, sorry that it's actually a link, because i don't have enough points yet to embed the image).
This one is pretty easy. Im not that great at python yet but i just tested it and it works as intended.
def isZero(val):
if val==0:
print('bye')
quit()
title = int(input('enter a number'))
ZeroCheck = isZero(title)
while title>0:
title = int(input('enter a number'))
isZero(title)

message.edit() takes 1 positional argument but 2 were given

I'm migrating a discord bot to the new discord.py api, there's a part of editing messages, and its giving me that error..
output = "new text"
await message.edit(output)
Doc
am I reading the docs wrong? sry not a python literate, just helping a friend
The documentation states that there are multiple fields which can be specified. In your case, you need to have content=output for the message to be edited.
Hope that helps!

Is there any exp_internal equivalent in Pexpect

I have recently started with pexpect and trying to learn it through the analogy with Tcl/Expect. Since I am come from the Tcl/Expect background, I believe there must be something like "exp_internal".
Can someone let me know what is equivalent of "exp_internal" of Tcl/Expect in pexpect terminology.
PS: exp_internal in Tcl/Expect prints all the log messages produced by the internal regex engine. It clearly shows what was the buffer received by the expect and what regular expression it matched or did't match.
EDIT
No answer seems to have existed back when the question was posted. I will just try to edit the question with hope that there now is an answer.
There is no such feature in pexpect

Windows 7, wxpython, unknown font weight

I'm kind of new at this:
My app works great in Linux, where I developed it. I'm trying to port it to win7 before making it an exe (the school psych wants to use it on her computer). One of the functions of the app is to change the font size in response to an event (in this case, the user presses a button).
Here's the code:
if countfinal == 1:
on_start = time.time()
ot.append(on_start)
self.welcome.SetLabel("Timing On Task Event")
self.label_directions.SetLabel("Timing On Task Event")
self.SetBackgroundColour(wx.GREEN)
on.append(1)
font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.DEFAULT, wx.FONTENCODING_SYSTEM)
self.label_directions.SetFont(font)
self.save_quit.Enable(False)
Windows 7 throws up this error:
Traceback (most recent call last):
File "time.py", line 131, in time_event
font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.DEFAULT, wx.FONTENCODING_SYSTEM)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 2081, in __init__
_gdi_.Font_swiginit(self,_gdi_.new_Font(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at ..\..\src \msw\font.cpp(560) in wxNativeFontInfo::Se
tWeight(): unknown font weight
I've been reading that it has something to do with Windows not using UTF-8. That's nice, but it doesn't help me.
How do I tell wx to use the font encoding Windows 7 recognizes? Could someone be so kind as to provide me with a code example that does this? The documentation is a little too cryptic for me; I'm still at that struggling neophyte stage with this.
I wrote an article about fonts on my blog. I just tried the code and added an 18 pt font to the "sizes" list and it worked fine. Maybe you could try it on your computer and see if it works there too? If it does, then you'll want to see where your code differs from mine.
Okay, I figured out where my mistake was on this one. I was doing two things wrong:
I was misreading the error code. The error code referred to "weight" and not "size." The whole utf-8 thing really was a rabbit hole to nowhere.
I was putting things in the wrong order. Mike Driscoll's tutorial makes it clear with this example:
font = wx.Font(size, families[family], styles[style],
weights[weight])
that wx is picky about the order of attributes. It goes size, family, style, weight. I had them out of order. I think I was also using the wrong wx attributes. It seems that some tutorials will include wx.DEFAULT rather than wx.FONTFAMILY_DEFAULT. That's wickedly confusing to a new programmer. Is it really that hard to just write out the first part of the tag? Especially in a tutorial?
Here's the code that works:
if countfinal == 1
size = 18
font = wx.Font(size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.label_directions.SetFont(font)
Special thanks to Mike Driscoll for posting an answer and for writing that tutorial!
Cheers!

Resources