使用Discord.Py发送消息

2024-05-14 17:27:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在尝试配置一个bot,它根据计时器发送消息!一切都很完美,我现在需要做的就是发送一条消息。我不知道该怎么做,因为它不是异步函数。我在网上搜索并查看了其他stack overflow帖子,但都没有结果,所以我来了。bot的代码如下所示:

async def lava_loop_code(ctx):
    global lava_variable_1
    global Lava_bot_online
    channel = discord.Object(id='804695089485840394')
    print("Lava", lava_variable_1) 
    lava_variable_1 = lava_variable_1 + 1
    if lava_variable_1 == number_of_seconds:
        await.channel.send("Hello World") #This is the line
        print("Lava offline")
        lava_variable_1 = 0
        Lava_bot_online = True
        lava_timer.cancel()

该代码通过以下函数调用:

    if message.channel.id == 709929044552187906: 
        print("message in lava_channel")
        lava_variable_1 = 0
        if Lava_bot_online == True:
            await channel.send("<Bot is online!") 
            print("Online")
            Lava_bot_online = False
        if lava_timer != None:
            lava_timer.cancel()
        lava_timer = setInterval(1, lava_loop_code)

在频道中显示Hello World需要我做什么?任何帮助都将不胜感激


Tags: 代码loopid消息ifbotchannelcode
1条回答
网友
1楼 · 发布于 2024-05-14 17:27:39

那一行await.channel.send("Hello World")给了您一个错误,因为在awaitchannel之间有一个.。你需要做await channel.send("Hello World")

async def lava_loop_code(ctx):
    global lava_variable_1
    global Lava_bot_online
    channel = discord.Object(id='804695089485840394')
    print("Lava", lava_variable_1) 
    lava_variable_1 = lava_variable_1 + 1
    if lava_variable_1 == number_of_seconds:
        await channel.send("Hello World") #This is the line
        print("Lava offline")
        lava_variable_1 = 0
        Lava_bot_online = True
        lava_timer.cancel()

相关问题 更多 >

    热门问题