Assignment to constant variable (DISCORD.JS) [duplicate] - discord

This question already has an answer here:
Assignment to constant variable exception
(1 answer)
Closed 11 months ago.
I have a probleme, I want to make a setprefix command like that:
if (message.content.startsWith(prefix + 'setprefix')) {
var usermsg = message.content.split(" ").slice(1).join(" ");
if (!usermsg[0]) return message.delete().then(console.log('[', 'ERROR'.red, ']', 'un argument est nécessaire'))
prefix = usermsg
const setprefix = (`prefix changé en: ${usermsg}`)
message.delete()
message.channel.send(setprefix)
}
but i have this error:
prefix = usermsg
^
TypeError: Assignment to constant variable.
What did I must do ?

According to your error, there appears to be a constant named as prefix and you are trying to change the value of the constant. This is a really easy mistake to make especially for beginners who have just started learning something in JavaScript. I would recommend that you actually take a course on learning basic JS before attempting Discord.JS since there are a lot of mistakes which can be made if you don't know the basics. For your question, all you have to do is, in the line of code where you declare the constant prefix, instead of using const prefix, change it to let prefix

Related

Discord Custom Emojis Showing Error while giving it a Variable in DISCORD.PY

I am Trying to Create a 'mine' command which gives you Economical Money
It is working fine and all and I decided to add an Emoji next to the item , So i decided to give the Variable names for each of the Emojis like so :
LANGUAGE IS DISCORD.PY
#declaring Emoji Variables
sEmoji = <:stone:900586388708290610>
cEmoji = <:coal:900586388708290610>
iEmoji = <:iron:900586388708290610>
gEmoji = <:gold:900586388708290610>
dEmoji = <:diamond:900586388708290610>
eEmoji = <:emerald:900586388708290610>
And the Console is Showing this
File "main.py", line 33
sEmoji = (<:stone:900586388708290610>)
^
SyntaxError: invalid syntax
I don't know what Syntax to Input there , Can you help me ?
All you need to do it put quotes around it. The < is being interpreted as a relational operator. Discord will "translate" the emoji for you.

For control variable already in use compile error

I am trying to write a nested for loop in visual basic macro which runs on excel.
Here is my simplified code
Dim intVar(2) As Integer
For intVar(1) = 0 To 4
For intVar(2) = intVar(1) To 4
Var = Var + intVar(1) + intVar(2)
Next intVar(2)
Next intVar(1)
When I try to compile the code "For control variable already in use" compile error is thrown. Is there any solution for using array variables for For Loop or should I declare different variables for each For Loop?
There are some questions with the same tag but none of them for the array type control variables. If you help me I would be glad.
Thank you for your interest

Reactjs convert input string to upper case

I'm creating an app in Reactjs using react-strap. I would like to convert an input field to upper case.
From googling, it looks like simply appending "toUpperCase()" to the field would work, but this doesn't appear as an option in Visual Studio code.
I had a similar issue with doing a replace all, but finally got that to work using "const" field:
// replace ":" with "-"
const phrase = item.macs;
const replaced = phrase.replace(/:/g, '-')
item.macs = replaced;
However, converting to a const field doesn't work for making the "toUpperCase()" available.
What should I do to turn this into a string so I can call the "toUpperCase()" function?
Edit: change references from "toUpper" to "toUpperCase". The problem is this is not available as a function.
For example of I do
'myString'.toUpperCase();
it works. But it I can't get it to bring that up in Visual Studio Code, and it's ignored if I code it anyway.
I believe you are looking after toUpperCase.
To make a string uppercase in javascript you can call .toUpperCase() method on it. For example
const foo = 'foo'
const fooUpper = foo.toUpperCase()
console.log(fooUpper) // expected result 'FOO'
I got around this problem by forcing the input item to be regarded as a string by prepending it with a '', like so:
item.macs = '' + item.macs;
item.macs = item.macs.replace(/:/g, '-');
item.macs = item.macs.toUpperCase();
After that, all the string functions were available.

Array from Request.Form in classic asp [duplicate]

This question already has an answer here:
String to Array with Classic ASP
(1 answer)
Closed 6 years ago.
EDIT: I now realise after the help from those who replied that my question was about whether Request.Form Data is a string in the same way that a$="FooBar" is a string and the Array command in Classic ASP.
I'm trying to make an Array from data submitted in a Form.
The form fields are dynamically created and have the same name "subj".
The Response.Write(Request.Form("subj")) produces:
"Welcome and Introduction, Talk1, Talk2 ,Interactive review of the conference"
When I check the TypeName or VarType Request.Form("subj") is a string. Then I code:
subjs = """" & Replace(Request.Form("subj"), ", ", """,""") & """"
subjects = Array(subjs)
With the intention to give:
subjs = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"
subjects(0) = Welcome and Introduction
subject(1) = Talk1
subject(2) = Talk2
subject(3) = Interactive review of the conference
The problem is that what I actually get is:
subjs = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"
subject(0) = "Welcome and Introduction","Talk1","Talk2","Interactive review of the conference"
For some reason the Array isn't correctly formed as there is no subject(1) subject(2) or subject(3).
If I physically copy and paste the output of subjs into my code, then Array works fine but I can't get the Array to work on Form Data.
I've tried using CStr and checked all of the quotation marks.
Why doesn't it work?
Thank you to those who took the trouble to reply. Whilst Split does work in fields without commas, SET var = Request.Form("subj") as per #Kul-Tigin, I think is the key but would be keen to hear other thoughts
Since the request collection values may contain commas, using a split can cause unexpected results.
Creating an array through the collection is more reliable.
Set subject = Request.Form("subj")
ReDim subjects(subject.Count - 1)
For i = 1 To subject.Count
subjects(i - 1) = subject(i)
Next
The Array function expects a comma-separated list: "words","stuff","foo", but what you get from a Request.Form is more like "words,stuff,foo".
Ultimately, though, it doesn't matter, because as you've noted in your comment, the appropriate function to use is Split.

Trouble with arrays and randomizing [duplicate]

This question already has answers here:
How to initialize properties that depend on each other
(4 answers)
Closed 7 years ago.
I have
var rockNamesArray:[String] = ["bird", "rock2", "rock3"]
var rockpos = Int(arc4random_uniform(UInt32(3)))
var firstrockString:String = self.rockNamesArray[rockpos]
But its telling me that rockNamesArray isnt a member. Help?
The following works perfectly in a playground.
import Foundation
var rockNamesArray:[String] = ["bird", "rock2", "rock3"]
var rockpos = Int(arc4random_uniform(UInt32(3)))
var firstrockString:String = rockNamesArray[rockpos]
it's not clear from your code if those variables are being declared inside a function or at the class level. The issue is the self. which refers to member variables so I assume the declaration is inside a function etc.
As ABakerSmith hinted - it's really easy to get to the bottom of these kinds of issues by copying & pasting the offending code into a playground.

Resources