TypeError '_Environ' object is not callable - discord

this show up everytime i try launch my discord bot. i tried to google but there wasnt anything good code is
bot.run(os.environ('TOKEN'))

os.environ is a dictionary object. Use os.environ['TOKEN'] or os.environ.get('TOKEN')

You should first import loadenv from a module called dotenv and than you can get the token from .env
pip install python-dotenv That how to install it using pip.
from dotenv import load_dotenv
load_dotenv["token"] # load_dotenv.get('token') work the same as the first one

Related

I keep getting a error while attempting to run my bot, module 'discord' has no attribute 'bot'

I am trying to run my bot currently and I keep running into the error “module 'discord' has no attribute 'bot'” and will not let me start my bot.
Here is my code:
import os
os.system("pip install py-cord")
import discord
import time
import requests
import datetime
from discord.ext import commands
from discord.utils import get from discord.ext import tasks
from discord.ext.commands import Bot
bot = discord.Bot()
#bot.event
async def on_ready():
print(f"WORKING AS {client.user}"
# commands were removed due to it not letting me post the question but the code shouldn’t be a issue with the bot. It is slash commands. I will leave the beginning of the code below.
#bot.slash_command(description="Unlock the chat.")
#commands.has_permissions(manage_channels = True)
# code was here
bot.run(mytoken)
I’ve already tried changing it from bot to client with no luck. I also already tried the specific version being 2b1. I want to use slash commands with the bot and client says there is no attribute slash commands.I do not think it’s something to do with the lower portion of the code, it’s something to do with the top of the code if you can help, please and thank you.
Your code looks perfectly fine.
However, this may be a library issue, and you're installing libraries in code (see below). If you accidentally installed discord.py, it may be causing this issue.
In the console do the following:
pip uninstall discord.py
This will uninstall discord.py
Then install the proper pycord version:
pip install -U py-cord==2.4.0
Why you want to do this manually
The reason you want to do this manually is that installing libraries in code is not supported by PIP. See more here.

How to use Sigma.js in React with Typescript

I'm trying to set up a simple web app with React/TypeScript so I can fiddle with some graphs with Sigma.js. But I can't get the end result to render anything with Sigma.
Here's the steps I followed:
$ npx create-react-app sigmafiddle --template typescript^C
$ cd sigmafiddle
$ yarn add sigma
$ yarn add #types/sigmajs
However, when I go to import Sigma I encounter the following problems:
import { sigma } from 'sigma'
Fails with this error message:
TypeScript error in ~/devel/sigmafiddle/src/App.tsx(4,23):
Could not find a declaration file for module 'sigma'. '~/devel/sigmafiddle/node_modules/sigma/endpoint.js' implicitly has an 'any' type.
Try npm install #types/sigma if it exists or add a new declaration (.d.ts) file containing declare module 'sigma'; TS7016
Not a real helpful message, since #types/sigma does not exist within npm.
And if I try this:
import { sigma } from 'sigmajs'
I get this failure:
TypeScript error in ~/devel/sigmafiddle/src/App.tsx(4,23):
File '~/devel/sigmafiddle/node_modules/#types/sigmajs/index.d.ts' is not a module. TS2306
I've also tried the package react-sigma:
yarn add react-sigma
// in app.tsx
import {Sigma, RandomizeNodePositions, RelativeSize} from 'react-sigma';
Unfortunately there is no #types/react-sigma package, so this results in the following error:
Cannot find module 'react-sigma'
How can I get sigma.js to work with TypeScript and React?
You didn't import what you are trying to use
replace
/// <reference types="#types/sigmajs" />
to
import { sigma } from 'sigma';
Usually, import as above is the common way to use lib in js/ts project.
Update
Since the error seems to be lacking type definition of the lib,
File '~/devel/graph-grammar/node_modules/#types/sigmajs/index.d.ts' is not a module.
npm install --save #types/sigmajs
And import as normal may work.
import { sigma } from 'sigma';
Refer to #types/sigmajs
Update No.2
You may need react-sigma npm, repo in your react project instead.
Install it, and import refer to the document seems fine.
import {Sigma, RandomizeNodePositions, RelativeSize} from 'react-sigma';
If that not work, try to install both sigma and react-sigma, since ploty.js need both ploty.js and react-ploty.js been installed, I guess you may meet the similar situation.
Update No.3
Seems react-sigma don't support typescript, they support flow-type instead.
Refer: document of react-sigma

AWS Amplify & React - Module not found: Can't resolve '#aws-amplify/analytics'

I am trying to add Login functionality to a React app I'm building using Amplify and AWS Cognito, but when I add the following line in my Login.js file:
Import {Auth} from "aws-amplify-react";
and try to compile, I get the following error:
Failed to compile.
./node_modules/aws-amplify-react/lib-esm/Analytics/trackLifecycle.js
Module not found: Can't resolve '#aws-amplify/analytics' in 'my_react_path/node_modules/aws-amplify-react/lib-esm/Analytics'
I tried installing Amplify with homebrew and npm, but I can't get around this, any tips?
EDIT:
Initially I had:
Import {Auth} from "aws-amplify";
But The compiler couldn't resolve aws-amplify, and I could only find aws-amplify-react in the node_modules folder so I changed it.
However, in "node_modules/aws-amplify-react/lib-esm/Analytics/trackLifecycle.js" in line 39:
import Analytics from '#aws-amplify/analytics';
The problem is that it can't find aws-amplify... Did I make a mess while installing maybe?
Assuming that you are not worried about bundle size at this stage, probably your easiest course of action is to remove your node_modules entirely, then:
npm i aws-amplify
import like this:
import Amplify, { Auth } from 'aws-amplify'
You only need to install/import aws-amplify-react if you plan on using the OOTB UI components. If you are making your own UI components for login you don't need that package at this stage.
I get a similar error
Failed to compile.
./node_modules/aws-amplify-react/lib-esm/Analytics/trackLifecycle.js
Module not found: Can't resolve '#aws-amplify/analytics' in '/Users/myuser/myproject/node_modules/aws-amplify-react/lib-esm/Analytics'
when following the Amplify tutorial.
The workaround I found is to execute:
npm i -S #aws-amplify/analytics #aws-amplify/interactions #aws-amplify/storage #aws-amplify/ui #aws-amplify/xr aws-amplify
Obviously, I would love to know how to avoid all these extra libraries.
I would revert to your previous version before attempting to add amplify (old package.json & node_modules)
Follow this walkthrough: https://docs.amplify.aws/start/getting-started/installation/q/integration/react-native
When you get to the "Add Authentication" step, skip it and go straight to "Next Steps" -> "Authentication" and follow until you get to:
import Amplify, {Auth} from 'aws-amplify';
import config from './aws-exports';
Amplify.configure(config);

How to use Google maps api with webpack and typescript

I'm trying to use google maps api in my react app using webpack and typescript.
i've tried installing this package:
npm install googlemaps
npm install #types/googlemaps
Then in my app
import * as GoogleMapsAPI from 'googlemaps';
I get the following error
[ts] File 'c:/MyAppFolder/node_modules/#types/GoogleMaps/index.d.ts' is not a module.
Not sure what I'm doing wrong
You don't need to import from "googlemaps". google.maps is a global variable declared in googlemaps/index.d.ts. So you can use google.maps in your code right away.
For example
const point = new google.maps.Point(0,0);
For more info about typescript module and namespace. You can follow this link

display the current npm version of my NodeJs app

I just want to display the version value of my package.json file within the footer of my app, but have no idea how to do that. I've read you could access those properties with process env object. Is it correct?
If you're running your app within NodeJs, you can access it by doing
process.env.npm_package_version
With ES6, you can also do
import {version} from './package.json';
The correct answers will be here in example:
Answer (this code include package.json file and get version)
const { version } = require('./package.json');
Answer
const version = process.env.npm_package_version
Please don't use JSON.parse, fs.readFile, fs.readFileSync and don't use another npm modules it's not necessary for this question.

Resources