discord.py(重写)如何对特定通道进行命令

时间:2020-10-16 02:03:07

标签: python discord.py-rewrite

我需要制作一个仅限于特定通道的命令。它会发送随机的汽车图片,但是我有一个名为“ Pics”的通道,我特别需要将命令范围缩小。你能帮我吗?

@client.command()
async def car(ctx):
    pictures = [
    'https://car-images.bauersecure.com/pagefiles/78294/la_auto_show_11.jpg',
    'http://www.azstreetcustom.com/uploads/2/7/8/9/2789892/az-street-custom-gt40-2_orig.jpg',
    'http://tenwheel.com/imgs/a/b/l/t/z/1967_firebird_1968_69_70_2000_camaro_blended_custom_supercharged_street_car_1_lgw.jpg',
    'https://rthirtytwotaka.files.wordpress.com/2013/06/dsc_0019.jpg',
    'http://speedhunters-wp-production.s3.amazonaws.com/wp-content/uploads/2008/06/fluke27.jpg',
    'https://i.ytimg.com/vi/pCt0KXC1tng/maxresdefault.jpg',
    'https://i2.wp.com/www.tunedinternational.com/featurecars/dorift/02.jpg'
    ]
    channel = discord.utils.get()
    if channel == 705161333972140072:
        await ctx.channel.purge(limit=1)
        await ctx.send(f'{random.choice(pictures)}')

1 个答案:

答案 0 :(得分:1)

替换为

channel = bot.get_channel(705161333972140072)
if ctx.channel == channel:
  await ctx.channel.purge(limit=1)
  await ctx.send(f'{random.choice(pictures)}')

从您的代码中删除

channel = discord.utils.get()
if channel == 705161333972140072:
    await ctx.channel.purge(limit=1)
    await ctx.send(f'{random.choice(pictures)}')

实际上,您犯了一个基本的语法错误!