【发布时间】:2021-01-23 01:26:53
【问题描述】:
我对@987654322@ 很陌生,我正在构建一个可以根据命令关闭的机器人(但这不会关闭/使机器人脱机,它只是禁用它的功能)。所以我做了这个shutdown() 命令,有时可以工作,而有时它对我来说不是未知的原因。有些打印也因为某种原因不能工作,我会在代码中标记它们:
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)
感谢转发!任何帮助表示赞赏!
【问题讨论】:
-
你可能想要
bot.logout()而不是.close() -
@effprime
Bot.logout只是Bot.close的别名,看看docs
标签: python discord discord.py dotenv