如何在 discord.py 中更改前缀命令?

时间:2021-07-07 08:59:10

标签: json discord discord.py bots prefix

所以,我按照教程制作了更改前缀命令,但是当我尝试更改前缀时,我什么也没得到。也没有错误。我尝试使用默认前缀运行其他命令,但它们也不起作用。我使用的代码是:

const About = () => {
    const classes = useStyles(); // To use the CSS Styles in styles.js
    return (
        <>
        <Navbar/>
        <Box component="div" className={classes.boxContainer}>
            <Typography className={classes.headerTitle} variant="h4">
                <Typed strings={["About Me"]}
                    typeSpeed={50}
                />
            </Typography>
            <br/>
            <Typography className={classes.headerSubtitle} variant="h5">
               Some content
                <br/>
               more content
                <br/>
                <br/>
                more content
                <br/>
                more content
                <br/>
                <br/>
                more content
                <br/>
                more content
                <br/>
                 and more content
            </Typography>
            <br/>
            <a href={CV} target="_blank">
                <Button
                    style={{
                        backgroundColor: '#ff6347',
                        textDecoration:"inherit"
                    }}
                    variant="outlined"
                    fullWidth={false}
                    endIcon={<SendIcon/>}
                >
                    Download CV
                </Button>
            </a>
        </Box>
        </>
    );
}

2 个答案:

答案 0 :(得分:0)

您需要将 process_commands(message) 添加到您的 on_message 事件

为什么会这样呢^^^^

@bot.event
async def on_message(msg):
    await bot.process_commands(msg) # add this line

答案 1 :(得分:0)

@Guddi 现在,当我尝试将前缀更改为“!”时,出现此错误:

Ignoring exception in on_message
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "main.py", line 55, in on_message
    await bot.process_commands(msg)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 975, in process_commands
    ctx = await self.get_context(message)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 886, in get_context
    prefix = await self.get_prefix(message)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 831, in get_prefix
    ret = await discord.utils.maybe_coroutine(prefix, self, message)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 341, in maybe_coroutine
    value = f(*args, **kwargs)
  File "main.py", line 23, in get_prefix
    prefixes = json.load(f)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)