我正在尝试使用python编码discord bot。 我想要包含这个迷你游戏,在那里我可以猜出一个随机数(在7次尝试中,这就是for循环的用途)。但我得到错误,我无法在代码中检测到。我老实说,这是错误的命令,但我不知道。
我尽可能清楚地编写了以下代码(我想是这样)。
#name of file: Experimental Drone 5
import random
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
drone = commands.Bot(command_prefix="!")
[...]
@drone.command(pass_context=True)
async def chat(ctx):
@drone.event
async def on_message(message):
[...]
elif message.content.startswith("guess number"): #line 54
await drone.send_message(message.channel, "text")
z = random.randint(1, 100)
for gT in range(1, 8):
await drone.say("Guess it!") #line 58
g = await drone.wait_for_message(int)
if g > z:
await drone.send_message(message.channel, "text")
elif g < z:
await drone.send_message(message.channel, "text")
else:
break
if g == z:
await drone.send_message(message.channel, "text")
else:
await drone.send_message(message.channel, "text. My number was
actually " + str(z)) #line 69
错误:(用户名已更改)
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\name\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:\Users\name\Desktop\Trustworthy Drones\Experimental Drone
5\Experimental Drone 5 .py", line 58, in on_message
await drone.say("Guess it!")
File "C:\Users\name\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\discord\ext\commands\bot.py", line 309, in _augmented_msg
msg = yield from coro
File "C:\Users\name\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\discord\client.py", line 1145, in send_message
channel_id, guild_id = yield from self._resolve_destination(destination)
File "C:\Users\name\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\discord\client.py", line 289, in _resolve_destination
raise InvalidArgument(fmt.format(destination))
discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel,
User, or Object. Received NoneType