【问题标题】:Output Python script to Discord bot将 Python 脚本输出到 Discord 机器人
【发布时间】:2020-11-11 17:49:09
【问题描述】:

我正在尝试将另一个 Python 脚本的输出添加到我的 Discord 机器人。 我的第一个脚本“clash.py”有效,我有一个结果:项目列表,它适用于我的操作系统(Raspbian) 当用户发送特定命令时,我想将它放在 Discord 上:!clantest

这种方式适用于:

import discord
from discord.ext import commands

TOKEN = 'Token'

description = '''Merluchon Bot'''
bot = commands.Bot(command_prefix='!', description=description)

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')

bot.command()
async def Mousse(ctx):
    """Cadeau pour le peuple"""
    await ctx.send("https://viesdamelie.files.wordpress.com/2014/07/bain.gif")

bot.run(TOKEN)

如何以这种方式在命令中添加“clash.py”的结果:

async def clantest(ctx):
    """Cadeau pour le peuple"""
    await ctx.send("clash.py")

即使我知道这不是它应有的方式,你也看到了这个想法。

非常感谢!!

【问题讨论】:

    标签: python discord bots


    【解决方案1】:

    你需要在 crash.py 文件中创建一个可调用函数

    类似

    def clash():
        <Code to execute>
    

    然后您可以在 discord bot 文件的顶部导入您的 crash.py 文件,就像您当前正在导入其他库(或文件)一样

    然后从你的 clantest bot 命令中你可以调用你的函数

    async def clantest(ctx):
        clash()
        await ctx.send(Whatever your clash function spits out)
    

    【讨论】:

    • 感谢您的回复!但是,在“无论你的冲突blabla”中,我应该放什么......?我希望出现 crash.py 的完整结果。
    • 我不知道你的冲突.py 文件输出什么,因为我没有看到它。当我不知道你的代码时,我很难确切知道该放什么
    • 输出如下所示: 名称:Nova l Askaa Trophies:5084 标签:#U8PLPCC 名称:Mika fureur 奖杯:5047 标签:#88PG2RPGP
    猜你喜欢
    • 2021-07-17
    • 1970-01-01
    • 2020-04-07
    • 2021-07-20
    • 2019-01-12
    • 2019-08-10
    • 2022-01-23
    • 1970-01-01
    • 2019-05-10
    相关资源
    最近更新 更多