''str' object is not callable Hangman command Discord
so i was making a hangman command but it just says 'str' object is not callable
that error message popped up when i was polishing the command please tell me how to fix it
heres my hangman code
gameStart = False
words = ["words i put"]
pickedword = "No picked words currently!"
def word_selected_dashed():
if pickedword == "No picked words currently!":
return
else:
global selectedword
selectedword = []
for i in range(len(pickedword)):
selectedword.append('?')
return ''.join(selectedword)
@client.command()
async def hangman(ctx):
global gameStart
global pickedword
global trials
pickedword = random.choice(words)
if gameStart == True:
await ctx.send("There is a game ongoing please use `sus hangmanstop` to stop")
else:
gameStart = True
await ctx.send("Game Started")
lettercount = 0
for letters in pickedword:
lettercount += 1
await ctx.send(f"This word has {lettercount} letters!")
word_selected_dashed()
@client.command()
async def guess(ctx, letterput : str):
getattr(str, 'lower')
letter = letterput.lower()
if pickedword == "No picked words currently!":
await ctx.send("No game found! Please use `sus hangman` to start a game!")
return False
if letter in alphabet and gameStart == True:
print(letter)
elif letter == pickedword:
await ctx.send("You guess the word!")
await hangmanstop(ctx)
return
elif gameStart == False:
await ctx.send("You havent started a game!")
return False
global guessed_word
global word_selected_dashed
global trials
trials = 7
word_selected_dashed = word_selected_dashed()
gussed_word = list(word_selected_dashed)
if letter in pickedword:
for i in range(len(pickedword)):
if list(pickedword)[i] == letter:
gussed_word[i] = letter
await ctx.send(''.join(gussed_word))
elif letter not in pickedword:
await ctx.send('wrong!')
trials -= 1
await ctx.send(f"You only have {trials} guesses left!")
if trials == 0:
await ctx.send("You lost!")
await hangmanstop(ctx)
return
@client.command()
async def hangmanstop(ctx):
global gameStart
if gameStart == True:
gameStart = False
await ctx.send("Current game stopped!")
else:
await ctx.send("No game found | Please use `sus hangman` to start a game!")
idk what is making the problem i looked at the terminal very closely but i cant find the code making it error i know its a str error but everytime i try to fix it same error please help me
Solution 1:[1]
You are looking for the “lower” attribute of a str callable on the first line of your guess method as highlighted below.
async def guess(ctx, letterput : str):
getattr(str, 'lower')
Remove the getattr() call altogether.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jarvis |
