簡體   English   中英

discord.py bot 未加入頻道

[英]discord.py bot not joining channel

好的,這是我的代碼

import discord
from discord.ext import commands

TOKEN = 'THIS_IS_MY_BOT_TOKEN'

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

@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return
    #typing cat
    if message.content.startswith('!cat'):
        msg = 'https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif'.format(message)
        await client.send_message(message.channel, msg)
    #I dont need sleep i need awnsers
    if message.content.startswith('!sleep'):
        msg = 'https://i.kym-cdn.com/entries/icons/original/000/030/338/New.jpg'.format(message)
        await client.send_message(message.channel, msg)
    #murica
    if message.content.startswith('!murica'):
        msg = 'https://www.dictionary.com/e/wp-content/uploads/2018/08/Murica_1000x700.jpg'.format(message)
        await client.send_message(message.channel, msg)
    if message.content.startswith('!why'):
        msg = 'https://drive.google.com/file/d/1rb132Y785zUjj2RP2G-a_yXBcNK5Ut9z/view?usp=sharing'.format(message)
        await client.send_message(message.channel, msg)
@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.command(pass_context=True)
async def join(ctx):
    if ctx.message.author.voice:
        channel = ctx.message.author.voice.channel
        await channel.connect()

client.run(TOKEN)

機器人加入服務器,但是當我說.join 時,什么也沒有發生

如果有幫助,我想加入的語音頻道稱為Club Meeting

不完全確定為什么,我運行它時沒有錯誤。 有人知道發生了什么嗎?

我認為問題在於您缺少Bot.process_commands您需要將其放在 on_message function 的末尾。 這似乎是您的命令不起作用的原因。

來自文檔:

為什么 on_message 使我的命令停止工作? https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM