Resolved and Fixed How do I close this? :D
I've been working none stop lately on adding features to my chat bot and occasionally come across an issue that I need assistance in. I've looked at other suggested threads already.
The Short Explanation:
Trying to get it to select a number between 1 and n. The command a user can
use would be /roll 20, this returns 1-20. I'm trying to be able to get args to replace random.randint(n)
while n = integer. Sorry if my explanation is bad. Been up days working nonstop.
The Original Code(python) before attempt:
elif used_prefix and cmd.lower() == "roll" and self.rank(user) >= 1:
args = args.lower()
if len(args) == 0: post("Select a dice amount(6,8,10,20)")
else:
if args == "6": post("Rolled %s" % random.randint(1,6))
elif args == "8": post("Rolled %s" % random.randint(1,8))
elif args == "10": post("Rolled %s" % random.randint(1,10))
elif args == "20": post("Rolled %s" % random.randint(1,20))
else: post("Select a dice amount(6,8,10,20")
The End Result Code(Python) after attempt:
elif used_prefix and cmd.lower() == "roll" and self.rank(user) >= 1:
args = args.lower()
n = args.lower()
if len(args) == 0: post("Select a dice amount(6,8,10,20)")
else:
post("Rolled %s" % str(random.randint(1,n)))
The Traceback
[STATUS] Setting status Online...
[LOAD] Loading Errors...
[LOAD] Loading Locks...
[SAVE] Appending default...
Connected
Connected
Youcoldyet(4)-[devlcars]:[/roll 20](Monday, 11 May 2015, 01:07:23 AM)
[ERR] Fatal error.
(C:\Python34\lib\random.py:218) Can't convert 'int' object to str implicitly
Traceback (most recent call last):
File "C:\Users\Administrator\Downloads\hmm\bot.py", line 575, in <module>
TestBot.easy_start(rooms, "Hidden", "Hidden")
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 1278, in easy_start
self.main()
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 1254, in main
con._feed(data)
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 550, in _feed
self._process(food.decode().rstrip("\r\n")) #numnumz ;3
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 560, in _process
getattr(self, func)(args)
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 670, in rcmd_u
self._callEvent("onMessage", msg.user, msg)
File "C:\Users\Administrator\Downloads\hmm\ck.py", line 957, in _callEvent
getattr(self.mgr, evt)(self, *args, **kw)
File "C:\Users\Administrator\Downloads\hmm\bot.py", line 447, in onMessage
post("Rolled %s" % str(random.randint(1,n)))
File "C:\Python34\lib\random.py", line 218, in randint
return self.randrange(a, b+1)
TypeError: Can't convert 'int' object to str implicitly
[96m[SAV][0m Saving Rooms..
[STATUS] Setting status Offline...
Waiting 30 seconds for you to read the error..
What I could do and try:
I'm trying to be able to get args to replace random.randint(n)
while n = integer. I could try doing n = args.lower()
However when I did that it returned a value error since I was
unable to get the second option selected, and that would force
users to use the command /roll n, n. I thought about trying to
set the new code to be random.randint(1,n)
Then setting n = args.lower()
, that would possibly allow roll selection.
Update
Tried my idea and it simply returned:
TypeError: Can't convert 'int' object to str implicitly
I even proceeded to change the line to post("Rolled %s" % str(random.randint(1,n)))
which failed
Oh and if you were wondering this is a roll command for Role Playing purposes Any and all feedback/suggestions are welcomed. I'm hoping to get this resolved.