所以我创建了一个不和谐的机器人,但我只能输入 1 个服务器和 1 个频道,我如何才能让机器人可以输入多个频道?
错误信息
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 20, in on_message
amount = int (message.content)
ValueError: invalid literal for int() with base 10: '!Start'
代码:
import discord
import os
client = discord.Client()
@client.event
async def on_ready():
print ('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!Start'):
await message.channel.send('Hi')
client.run(os.getenv('TOKEN'))
答案 0 :(得分:0)
你使用的是 discord.js 还是 discord.py?无论哪种方式,除非您有充分的理由,否则最好使用
client = commands.Bot(command_prefix = "-")
@client.command()
async def Start(ctx):
await ctx.send("Hi")
抱歉,这不能回答您的问题,但它可以提供一种使用不同方法实现结果的方法。此外,如果您正在使用 discord.py 重写,那么在没有 async def on_message(message):
结尾的情况下执行 await client.process_commands(message)
可能会破坏很多事情,因此请尝试将其添加到您的函数中。