【问题标题】:I want Discord bot to write another python script output with comand我希望 Discord bot 使用命令编写另一个 python 脚本输出
【发布时间】:2020-12-20 13:19:22
【问题描述】:

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

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

【问题讨论】:

    标签: python scripting command discord


    【解决方案1】:

    假设两个脚本在同一个文件夹中:

    #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())
    

    【讨论】:

    • 脚本现在可以读取其他脚本,但是我如何制作命令来使用它并将其打印为命令我对此很不好,我不明白这部分
    • 我不太了解你的问题,也许用两个文件中的代码更新你的问题,并解释你要运行什么代码?
    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 2021-03-01
    • 2018-07-21
    • 2021-05-17
    • 2021-04-11
    • 1970-01-01
    • 2020-12-20
    • 2021-01-19
    相关资源
    最近更新 更多