微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我希望Discord机器人使用comand

如何解决我希望Discord机器人使用comand

我确实构建了一个不和谐的机器人,我想添加一个命令来运行并读取python中的另一个脚本输出 我该怎么做? 这是我不和谐的新机器人

import discord
from discord.ext import commands,tasks

import discord
from discord.ext import commands,tasks
from itertools import cycle

flashing = commands.Bot(command_prefix='.')

@flashing.command()

async def ping(ctx):
    await ctx.send(f'Pong! {round(flashing.latency * 1000)} ms' )
    print('bot is ready.')

@flashing.event
async def on_ready():
    change_status.start()


flashing.run('token')

一个脚本名称是base_script.py

解决方法

假设两个脚本位于同一文件夹中

#scripts.py
def Some_Code():
    #Put all of scripts.py code in this function
    return(Variables)
    #make sure to return all variable that you want to read in your other file

假设您已经设置了scripts.py,其余的操作很简单:

import scripts
print(scripts.Some_Code())

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。