I am pretty new to discord.py
thing and I am building a bot that can I shut down on command(but that doesn't turn off/make bot offline, it just disables it's functions). so I made this shutdown()
command and sometimes works and other times it doesn't for some to me unknown reason. Some prints don't work either for some reason, I will mark them in the code:
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
import random
load_dotenv()
token = 'bot token'
bot = commands.Bot(command_prefix = '$')
@bot.event
async def on_ready():
print('-----------------------------------')
print('we have logged in as {0.user}'.format(bot))
print('-----------------------------------')
@bot.command()
async def ping(ctx):
await ctx.channel.send("pong")
@bot.command()
async def say(ctx, *args):
response = ""
for arg in args:
response = response + " " + arg
await ctx.channel.send(response)
@bot.command()
async def shutdown(ctx):#this command doesn't work properly
await bot.close()
print("We have logged off as {0.user}".format(bot))#this print doesn't work most of the time
@bot.event
async def on_message(message):
if message.content == "opinion":
await message.channel.send("not an opinion")
bot.run(token)
Thanks in forward!Any help is appreciated!
question from:
https://stackoverflow.com/questions/65848915/discord-bot-command-works-some-times 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…