Код: Выделить всё
import discord
import os
import asyncio
cchannel = 1257783751249891361
cdm = 962026630497321000
token = os.environ['toke']
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
print(message.content)
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
async def command_loop():
while True:
global cchannel
global cdm
commando = input("$ ")
commandy = commando.split(" ", 1)
command = commando.split(" ", 1)[0]
if command == "exit":
print("Shutting down the bot...")
await client.close()
break
elif command == "say":
print(commandy[1])
cchannel2 = await client.fetch_channel(cchannel)
await cchannel2.send(commandy[1])
elif command == "setchannel":
print(commandy[1])
cchannel = commandy[1]
elif command == "setdm":
print(commandy[1])
cdm = commandy[1]
elif command == "dm":
print(commandy[1])
cdm2 = await client.fetch_user(cdm)
await cdm2.send(commandy[1])
else:
print(f"Command received: {command}")
async def main():
bot_task = asyncio.create_task(client.start(token))
loop_task = asyncio.create_task(command_loop())
done, pending = await asyncio.wait(
[bot_task, loop_task],
return_when=asyncio.FIRST_COMPLETED
)
for task in pending:
task.cancel()
asyncio.run(main())
Подробнее здесь: https://stackoverflow.com/questions/792 ... oesnt-work
Мобильная версия