python - 我希望 Discord bot 用命令编写另一个 python 脚本输出
问题描述
我确实构建了一个不和谐的机器人,我想添加一个运行并在 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())
推荐阅读
- javascript - 解析具有未定义值的 JSON?
- python - 删除 SQL Server Express 中的重复行
- python - 将非线性激活函数与 softmax 结合使用时,自动编码器的结果不佳
- python - 合并熊猫中的两个数据框并在合并后将column_x与column_y合并
- sql-server - 从 Python 将 SSRS 报告导出为 PDF
- angular - 当有 route.paramMap.subscribe 时,是否有任何理由使用 route.snapshot.paramMap?
- xml - XSLT - 从具有相同属性名称的元素创建属性值数组
- angularjs - 从 AngularJS 调用时,Angular 路由器不更新浏览器 URL
- angular - Angular 6 - 过滤后单击表格行返回错误值
- flutter - 未处理的异常:错误状态:无法设置内容类型为“application/json”的请求的正文字段